HttpServer.close doesn't block long enough #4155
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
library-io
The HttpServer.close method returns immediately, without waiting for the server to actually close. This means that if another server starts listening on the same port immediately after the first server is closed, it will fail. If some code runs before the second server starts listening, you have a race condition; if the interstitial code takes long enough, the second server will work, but if it executes quickly then you'll get a port conflict. This is what caused this build breakage: http://chromegw.corp.google.com/i/client.dart/builders/vm-mac-release/builds/4814/steps/tests/logs/stdio
Here's some example code:
var server1 = new HttpServer();
server1.listen('127.0.0.1', 3123);
server1.close();
// Code here causes a race condition
var server2 = new HttpServer();
server2.listen('127.0.0.1', 3123); // error: port 3123 already in use
An alternate solution would be to have HttpServer provide some asynchronous notification of when it was actually closed, such as #close returning a Future.
The text was updated successfully, but these errors were encountered: