Skip to content

Commit 11628dd

Browse files
committed
make sure all request types await responses
On OSX ARM accepting sockets would fail because the sender side (dcd-client) was generating, sending the whole packet and closing the socket faster than phobos was with accepting the socket, causing an exception in setOption inside socket.accept, which is now commented in the code as well.
1 parent cc8f088 commit 11628dd

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/dcd/client/client.d

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ int runClient(string[] args)
151151
request.kind = RequestKind.clearCache;
152152
Socket socket = createSocket(socketFile, port);
153153
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
154-
return sendRequest(socket, request) ? 0 : 1;
154+
if (!sendRequest(socket, request))
155+
return 1;
156+
return getResponse(socket).completionType == "ack" ? 0 : 2;
155157
}
156158
else if (addedImportPaths.length > 0 || removedImportPaths.length > 0)
157159
{
@@ -165,15 +167,16 @@ int runClient(string[] args)
165167
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
166168
if (!sendRequest(socket, request))
167169
return 1;
168-
return 0;
170+
return getResponse(socket).completionType == "ack" ? 0 : 2;
169171
}
170172
}
171173
else if (listImports)
172174
{
173175
request.kind |= RequestKind.listImports;
174176
Socket socket = createSocket(socketFile, port);
175177
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
176-
sendRequest(socket, request);
178+
if (!sendRequest(socket, request))
179+
return 1;
177180
AutocompleteResponse response = getResponse(socket);
178181
printImportList(response);
179182
return 0;

src/dcd/server/main.d

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)