| Index: dart/runtime/bin/eventhandler_android.cc | 
| diff --git a/dart/runtime/bin/eventhandler_android.cc b/dart/runtime/bin/eventhandler_android.cc | 
| index b84cfc64f8f28175e70de11bd92328cf2405c09d..14cddc1554b13339e9fa625e5db645b1ae413607 100644 | 
| --- a/dart/runtime/bin/eventhandler_android.cc | 
| +++ b/dart/runtime/bin/eventhandler_android.cc | 
| @@ -223,13 +223,15 @@ void EventHandlerImplementation::HandleInterruptFd() { | 
| // We only close the socket file descriptor from the operating | 
| // system if there are no other dart socket objects which | 
| // are listening on the same (address, port) combination. | 
| +          ListeningSocketRegistry *registry = | 
| +              ListeningSocketRegistry::Instance(); | 
|  | 
| -          // TODO(dart:io): This assumes that all sockets listen before we | 
| -          // close. | 
| -          // This needs to be synchronized with a global datastructure. | 
| -          if (new_mask == 0) { | 
| -            socket_map_.Remove( | 
| -                GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 
| +          MutexLocker locker(registry->mutex()); | 
| + | 
| +          if (registry->CloseSafe(fd)) { | 
| +            ASSERT(new_mask == 0); | 
| +            socket_map_.Remove(GetHashmapKeyFromFd(fd), | 
| +                               GetHashmapHashFromFd(fd)); | 
| di->Close(); | 
| delete di; | 
| } | 
|  |