MINA
  1. MINA
  2. DIRMINA-819

Synchronous behavior while adding and removing connections

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-RC1, 2.0.0, 2.0.1, 2.0.2
    • Fix Version/s: 2.0.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

      Description

      We discovered some blocking behavior in the Mina AbstractPollingIoProcessor that is triggered while adding and removing connections.

      This class manages an internal worker that must be started when the first connection is added, and stopped when the last connection is removed.

      The code achieves this by using a synchronized block in startupProcessor() as follows:

      public final void remove(T session)

      { scheduleRemove(session); startupProcessor(); }

      private void scheduleRemove(T session)

      { removingSessions.add(session); }

      private void startupProcessor() {
      synchronized (lock) {
      if (processor == null)

      { processor = new Processor(); executor.execute(new NamePreservingRunnable(processor, threadName)); }

      }

      // Just stop the select() and start it again, so that the processor
      // can be activated immediately.
      wakeup();
      }

      Each call to session.close() triggers the "filterClose" event on the filter chain, ending in a call to removeSession (shown above) where the synchronized lock is obtained to verify that the processor is running in order to close the connection. When a large number of connections are closed at the same time, they will contend for the synchronized lock. Similar behavior occurs when new connections are established via addSession (not shown here). Both removeSession and addSession synchronize on the same lock, so they also contend with each other as connections come and go.

      Note that we found similar behavior in AbstractPollingIoAcceptor and AbstractPollingIoConnector as well.

      1. sync.patch
        10 kB
        John R. Fallows

        Activity

        Hide
        John R. Fallows added a comment -

        Patch relative to 2.0.0-RC1 where issue was first discovered.

        Show
        John R. Fallows added a comment - Patch relative to 2.0.0-RC1 where issue was first discovered.
        Hide
        Emmanuel Lecharny added a comment -
        Show
        Emmanuel Lecharny added a comment - Applied the provided patch into the 2.0.3 branch : http://svn.apache.org/repos/asf/mina/branches/2.0.3/ http://svn.apache.org/viewvc?rev=1070902&view=rev
        Hide
        Emmanuel Lecharny added a comment -

        Ok, applied. It's in the 2.0.3 branch, so you'll have to build it from there.

        Thanks !l

        Show
        Emmanuel Lecharny added a comment - Ok, applied. It's in the 2.0.3 branch, so you'll have to build it from there. Thanks !l

          People

          • Assignee:
            Emmanuel Lecharny
            Reporter:
            John R. Fallows
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development