@@ -197,7 +197,19 @@ int runServer(string[] args)
197197
198198 serverLoop: while (true )
199199 {
200- auto s = socket.accept();
200+ Socket s;
201+ try
202+ {
203+ s = socket.accept();
204+ }
205+ catch (SocketOSException e)
206+ {
207+ // happens on OSX when remote closes the connection before we finished accepting
208+ // fails internally in phobos with it trying to set socket option SO_NOSIGPIPE with "Invalid argument"
209+ // See https://bugs.gnunet.org/view.php?id=5825
210+ error(" unexpected internal error while acceping" );
211+ continue ;
212+ }
201213 s.blocking = true ;
202214
203215 if (useTCP)
@@ -224,6 +236,11 @@ int runServer(string[] args)
224236
225237 sw.reset();
226238 sw.start();
239+ scope (exit)
240+ {
241+ sw.stop();
242+ info(" Request processed in " , sw.peek);
243+ }
227244
228245 size_t messageLength;
229246 // bit magic!
@@ -252,34 +269,41 @@ int runServer(string[] args)
252269 {
253270 info(" Clearing cache." );
254271 cache.clear();
272+ s.trySendResponse(AutocompleteResponse.ack, " Could not reply ack" );
273+ continue ;
255274 }
256275 else if (request.kind & RequestKind.shutdown)
257276 {
258277 info(" Shutting down." );
278+ s.trySendResponse(AutocompleteResponse.ack, " Could not reply ack" );
259279 break serverLoop;
260280 }
261281 else if (request.kind & RequestKind.query)
262282 {
263- s.sendResponse (AutocompleteResponse.ack);
283+ s.trySendResponse (AutocompleteResponse.ack, " Could not reply ack " );
264284 continue ;
265285 }
266286
287+ bool needResponse;
288+
267289 if (request.kind & RequestKind.addImport)
268290 {
269291 cache.addImportPaths(request.importPaths);
292+ needResponse = true ;
270293 }
271294
272295 if (request.kind & RequestKind.removeImport)
273296 {
274297 cache.removeImportPaths(request.importPaths);
298+ needResponse = true ;
275299 }
276300
277301 if (request.kind & RequestKind.listImports)
278302 {
279303 AutocompleteResponse response;
280304 response.importPaths = cache.getImportPaths().map! (a => cast () a).array();
281305 info(" Returning import path list" );
282- s.sendResponse (response);
306+ s.trySendResponse (response, " Could not send import path list " );
283307 }
284308 else
285309 {
@@ -289,12 +313,12 @@ int runServer(string[] args)
289313 && ! request.sourceCode.length)
290314 {
291315 warning(" Received a " , request.kind, " request without source code" );
292- s.sendResponse (AutocompleteResponse.init);
316+ s.trySendResponse (AutocompleteResponse.init, " Could not send error response " );
293317 }
294318 else if (request.kind & RequestKind.autocomplete)
295319 {
296320 info(" Getting completions" );
297- s.sendResponse (complete(request, cache));
321+ s.trySendResponse (complete(request, cache), " Could not get completions " );
298322 }
299323 else if (request.kind & RequestKind.doc)
300324 {
@@ -304,13 +328,12 @@ int runServer(string[] args)
304328 else if (request.kind & RequestKind.symbolLocation)
305329 s.trySendResponse(findDeclaration(request, cache), " Could not get symbol location" );
306330 else if (request.kind & RequestKind.search)
307- s.sendResponse (symbolSearch(request, cache));
331+ s.trySendResponse (symbolSearch(request, cache), " Could not perform symbol search " );
308332 else if (request.kind & RequestKind.localUse)
309333 s.trySendResponse(findLocalUse(request, cache), " Couldnot find local usage" );
334+ else if (needResponse)
335+ s.trySendResponse(AutocompleteResponse.ack, " Could not send ack" );
310336 }
311-
312- sw.stop();
313- info(" Request processed in " , sw.peek);
314337 }
315338 return 0 ;
316339}
0 commit comments