pires / android-obd-reader

Android OBD-II Reader application that uses pure OBD-II PID's Java API.
Apache License 2.0
805 stars 470 forks source link

Can't Interrupt reading thread while Executing queue #163

Closed Kolyall closed 8 years ago

Kolyall commented 8 years ago

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 8 years ago

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