Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: pkg/analysis_server/lib/http_server.dart

Issue 237793002: Fix race condition with "server already started" error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/protocol.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/http_server.dart
diff --git a/pkg/analysis_server/lib/http_server.dart b/pkg/analysis_server/lib/http_server.dart
index fb88f79455b26975f3f3c298ba34dfe2c6c8bdce..9ddafb5170090da2db98229e14a77e4df073eda9 100644
--- a/pkg/analysis_server/lib/http_server.dart
+++ b/pkg/analysis_server/lib/http_server.dart
@@ -12,6 +12,7 @@ import 'package:analysis_server/src/domain_context.dart';
import 'package:analysis_server/src/domain_server.dart';
import 'package:analysis_server/src/get_handler.dart';
import 'package:args/args.dart';
+import 'package:analysis_server/src/protocol.dart';
Brian Wilkerson 2014/04/14 21:25:43 nit: I believe that we're generally keeping the im
/**
* Instances of the class [HttpServer] implement a simple HTTP server. The
@@ -98,10 +99,6 @@ class HttpAnalysisServer {
httServer.listen((HttpRequest request) {
List<String> updateValues = request.headers[HttpHeaders.UPGRADE];
if (updateValues != null && updateValues.indexOf('websocket') >= 0) {
- if (analysisServer != null) {
- _returnServerAlreadyStarted(request);
- return;
- }
WebSocketTransformer.upgrade(request).then((WebSocket websocket) {
_handleWebSocket(websocket);
});
@@ -129,6 +126,17 @@ class HttpAnalysisServer {
* running an analysis server on a [WebSocket]-based communication channel.
*/
void _handleWebSocket(WebSocket socket) {
+ ServerCommunicationChannel serverChannel = new WebSocketServerChannel(socket);
+ if (analysisServer != null) {
+ // TODO(paulberry): add a message to the protocol so that the server can
+ // inform the client of a successful connection.
+ var error = new RequestError.serverAlreadyStarted();
+ serverChannel.sendResponse(new Response('', error));
+ serverChannel.listen((Request request) {
+ serverChannel.sendResponse(new Response(request.id, error));
+ });
+ return;
+ }
analysisServer = new AnalysisServer(new WebSocketServerChannel(socket));
_initializeHandlers(analysisServer);
if (getHandler != null) {
@@ -158,18 +166,6 @@ class HttpAnalysisServer {
}
/**
- * Return an error in response to an UPGRADE request received after the server
- * has already been started by a previous UPGRADE request.
- */
- void _returnServerAlreadyStarted(HttpRequest request) {
- HttpResponse response = request.response;
- response.statusCode = HttpStatus.SERVICE_UNAVAILABLE;
- response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
- response.write('The server has already been started');
- response.close();
- }
-
- /**
* Return an error in response to an unrecognized request received by the HTTP
* server.
*/
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698