Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-813

Starvation occures sometimes in SerialSession#close()

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.8
    • Component/s: Transport
    • Labels:
      None
    • Environment:
      OS: Win32 XP-Pro
      rxtx Version :2.1.7.4_v20071016

      Description

      It seems that an starvation occures sometimes when we call close(true) on a SerialSession, the method never returns.
      We observed this case with JConsole, they are no Deadlocks detectable, so we assume that we have a starvation here.

      Here are the Stack traces of 2 involved Threads :
      ---------------------------------------------------------------------------------------------------
      Name: Thread-17
      State: RUNNABLE
      Total blocked: 0 Total waited: 0

      Stack trace:
      gnu.io.RXTXPort.eventLoop(Native Method)
      gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
      ---------------------------------------------------------------------------------------------------

      Name: Worker-6
      State: TIMED_WAITING
      Total blocked: 32.336 Total waited: 2.860

      Stack trace:
      java.lang.Thread.sleep(Native Method)
      gnu.io.RXTXPort.close(RXTXPort.java:1025)

      • locked gnu.io.RXTXPort@16ba7f9
        org.apache.mina.transport.serial.SerialSessionImpl$SerialIoProcessor.remove(SerialSessionImpl.java:302)
        org.apache.mina.transport.serial.SerialSessionImpl$SerialIoProcessor.remove(SerialSessionImpl.java:1)
        org.apache.mina.core.filterchain.DefaultIoFilterChain$HeadFilter.filterClose(DefaultIoFilterChain.java:634)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterClose(DefaultIoFilterChain.java:525)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1500(DefaultIoFilterChain.java:46)
        org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterClose(DefaultIoFilterChain.java:813)
        org.apache.mina.core.filterchain.IoFilterAdapter.filterClose(IoFilterAdapter.java:143)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterClose(DefaultIoFilterChain.java:525)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1500(DefaultIoFilterChain.java:46)
        org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterClose(DefaultIoFilterChain.java:813)
        org.apache.mina.core.filterchain.IoFilterAdapter.filterClose(IoFilterAdapter.java:143)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterClose(DefaultIoFilterChain.java:525)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1500(DefaultIoFilterChain.java:46)
        org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterClose(DefaultIoFilterChain.java:813)
        org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.filterClose(DefaultIoFilterChain.java:740)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterClose(DefaultIoFilterChain.java:525)
        org.apache.mina.core.filterchain.DefaultIoFilterChain.fireFilterClose(DefaultIoFilterChain.java:518)
        org.apache.mina.core.session.AbstractIoSession.close(AbstractIoSession.java:272)
        org.apache.mina.core.session.AbstractIoSession.close(AbstractIoSession.java:254)

        Activity

        Hide
        christian_schwarz Christian Schwarz added a comment -

        Probably this Bug is decribed here:

        Show
        christian_schwarz Christian Schwarz added a comment - Probably this Bug is decribed here: Several errors in RXTXPort.close() (blocks if RXTXPort.read() is blocking) http://bugzilla.qbang.org/show_bug.cgi?id=46 Port Locking during simultaneous close() calls on more than one Serial Port http://bugzilla.qbang.org/show_bug.cgi?id=60
        Hide
        christian_schwarz Christian Schwarz added a comment - - edited

        Workaround 1
        Closing from an other Thread
        http://il.youtube.com/watch?v=3nLCpopO2UM&feature=related

        class CloseThread extends Thread { 
          public void run() { 
            serialPort.removeEventListener(); 
            serialPort.close(); 
          }
        } 
        public void closePort() {
          try { 
            if (serialPort != null) { 
              serialPort.getInputStream().close(); 
              serialPort.getOutputStream().close(); 
              new CloseThread().start(); 
            }
         } catch (Exception e) {} 
        }
        
        Show
        christian_schwarz Christian Schwarz added a comment - - edited Workaround 1 Closing from an other Thread http://il.youtube.com/watch?v=3nLCpopO2UM&feature=related class CloseThread extends Thread { public void run() { serialPort.removeEventListener(); serialPort.close(); } } public void closePort() { try { if (serialPort != null ) { serialPort.getInputStream().close(); serialPort.getOutputStream().close(); new CloseThread().start(); } } catch (Exception e) {} }
        Hide
        christian_schwarz Christian Schwarz added a comment - - edited

        Workaround 2
        Hack the IOLock of the RXTXPort
        http://mango.serotoninsoftware.com/forum/posts/list/297.page (Comment #6)

        package gnu.io;
          
         public final class RXTXHack {
          
             private RXTXHack() {
                 
             }
             
             public static void closeRxtxPort(RXTXPort port) {
                 port.IOLocked = 0;
                 port.close();
             }
         }
        
        Show
        christian_schwarz Christian Schwarz added a comment - - edited Workaround 2 Hack the IOLock of the RXTXPort http://mango.serotoninsoftware.com/forum/posts/list/297.page (Comment #6) package gnu.io; public final class RXTXHack { private RXTXHack() { } public static void closeRxtxPort(RXTXPort port) { port.IOLocked = 0; port.close(); } }

          People

          • Assignee:
            Unassigned
            Reporter:
            christian_schwarz Christian Schwarz
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development