Improved truncated record detection and shutdown

- close serial on object deletion and stop background thread