pires/android-obd-reader

Can't Interrupt reading thread while Executing queue

Kolyall opened this issue · 1 comments

Here is code of ObdGatewayService.class
...........
protected void executeQueue() throws InterruptedException {

    Log.d(TAG, "Executing queue..");
    while (!Thread.currentThread().isInterrupted()) {
        ObdCommandJob job = null;
        try {
            job = jobsQueue.take();`

            // log job
            Log.d(TAG, "Taking job[" + job.getId() + "] from queue..");

            if (job.getState().equals(ObdCommandJobState.NEW)) {
                Log.d(TAG, "Job state is NEW. Run it..");
                job.setState(ObdCommandJobState.RUNNING);
                job.getCommand().run(sock.getInputStream(), sock.getOutputStream());`

...........
BUG: If OutputStream is closed or InputStream is closed before run of ObdCommand by this line: job.getCommand().run(sock.getInputStream(), sock.getOutputStream());
"receiving data..." command doesn't stop. No any Exception. Log stops on line :
I/ObdGatewayService: Taking job[45] from queue..
E/ObdGatewayService: Job state is NEW. Run it..

May be you can add a timeout for read?
To reproduce the issue:

  1. Connect to device,
  2. Run the ObdGatewayService, -> All works fine
  3. Go away from your car, or turn off ELM327 device from your car
    [bug] Reproduced
pires commented

Interesting! Thank you for reporting, will look into it.