DCD icon indicating copy to clipboard operation
DCD copied to clipboard

Unable to set socket option: Invalid argument

Open jacob-carlborg opened this issue 9 years ago • 4 comments

I've been using DCD for a while now and it's been working perfectly fine. Suddenly it stopped working. When I start the server and then call the client to add an import path I get this error:

2016-08-17T10:42:17.824:server.d:main:133 Starting up...
2016-08-17T10:42:17.824:server.d:main:167 Listening at /var/tmp/dcd-501.socket
2016-08-17T10:42:17.824:server.d:main:184 Import directories:

2016-08-17T10:42:17.824:server.d:main:190 0 symbols cached.
2016-08-17T10:42:17.824:server.d:main:191 Startup completed in 0.279186 milliseconds.
2016-08-17T10:42:23.231:server.d:main:174 Shutting down sockets...
2016-08-17T10:42:23.231:server.d:main:179 Sockets shut down.
std.socket.SocketOSException@std/socket.d(3138): Unable to set socket option: Invalid argument
----------------
4   dcd-server                          0x000000010b305b8f @trusted void std.socket.Socket.setOption(std.socket.SocketOptionLevel, std.socket.SocketOption, void[]) + 155
5   dcd-server                          0x000000010b305bec @trusted void std.socket.Socket.setOption(std.socket.SocketOptionLevel, std.socket.SocketOption, int) + 80
6   dcd-server                          0x000000010b3049cb @safe void std.socket.Socket.setSock(std.socket.socket_t) + 31
7   dcd-server                          0x000000010b3050de @trusted std.socket.Socket std.socket.Socket.accept() + 186
8   dcd-server                          0x000000010b176cd9 _Dmain + 2169
9   dcd-server                          0x000000010b2d9fbf D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 39
10  dcd-server                          0x000000010b2d9ef3 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) + 35
11  dcd-server                          0x000000010b2d9f64 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() + 44
12  dcd-server                          0x000000010b2d9ef3 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) + 35
13  dcd-server                          0x000000010b2d9e59 _d_run_main + 497
14  dcd-server                          0x000000010b1779f7 main + 15
15  libdyld.dylib                       0x00007fff8aaf55ac start + 0
16  ???                                 0x0000000000000000 0x0 + 0

I compiled DCD from source (10374061eabe9aab4ce721412933e4dc34970fc8), using DMD v2.071.1. I'm running on OS X. It seems like using TCP socket instead of Unix socket works.

jacob-carlborg avatar Aug 17 '16 08:08 jacob-carlborg

After some debugging I've kind of figured out what is the problem. The problem is this line [1] in std.socket.Socket. Or rather not taking into account the behavior when the SO_NOSIGPIPE option is used, which is only available on macOS.

I've found a bug report for zeromq [2] which seems to be the same issue, that states that the call to set the socket option can fail if the remote end has closed/reset the socket. I believe the solution is to try to reconnect. That other bug has been fixed here [3].

[1] https://github.com/dlang/phobos/blob/22799fffa0f279d62574e3ea20efccaf5c0b1f05/std/socket.d#L2602 [2] https://github.com/zeromq/libzmq/issues/1442 [3] https://github.com/zeromq/libzmq/commit/ceb6be7751ee44bca0a7b99ce8132381bf454ea7

jacob-carlborg avatar May 17 '17 19:05 jacob-carlborg

I believe the solution is to try to reconnect.

Since the problem is on the server side, reconnecting is not meaningful - we are only accepting connections from the client. So, the question is why would the client drop the connection immediately after connecting. Perhaps the IDE is killing the client process?

Can you still reproduce this problem, and if so, could you post complete steps to reproduce it?

CyberShadow avatar Jan 13 '19 00:01 CyberShadow

Just compiled with git master at 144cc4ed4133540d5017c5f1598cafb3df5766f5:

$ dmd --version
DMD64 D Compiler v2.084.0

$ make -j 16
git describe --tags > bin/githash.txt
mkdir -p bin
mkdir -p bin
dmd src/dcd/common/constants.d src/dcd/common/constants2.d src/dcd/common/dcd_version.d src/dcd/common/messages.d src/dcd/common/socket.d src/dcd/client/client.d msgpack-d/src//msgpack/attribute.d msgpack-d/src//msgpack/buffer.d msgpack-d/src//msgpack/common.d msgpack-d/src//msgpack/exception.d msgpack-d/src//msgpack/package.d msgpack-d/src//msgpack/packer.d msgpack-d/src//msgpack/register.d msgpack-d/src//msgpack/streaming_unpacker.d msgpack-d/src//msgpack/unpacker.d msgpack-d/src//msgpack/value.d -Imsgpack-d/src -Imsgpack-d/src -Jbin -inline -O -wi -ofbin/dcd-client
dmd src/dcd/common/constants.d src/dcd/common/constants2.d src/dcd/common/dcd_version.d src/dcd/common/messages.d src/dcd/common/socket.d src/dcd/server/autocomplete/complete.d src/dcd/server/autocomplete/doc.d src/dcd/server/autocomplete/localuse.d src/dcd/server/autocomplete/package.d src/dcd/server/autocomplete/symbols.d src/dcd/server/autocomplete/util.d src/dcd/server/main.d src/dcd/server/server.d dsymbol/src/dsymbol/builtin/names.d dsymbol/src/dsymbol/builtin/symbols.d dsymbol/src/dsymbol/cache_entry.d dsymbol/src/dsymbol/conversion/first.d dsymbol/src/dsymbol/conversion/package.d dsymbol/src/dsymbol/conversion/second.d dsymbol/src/dsymbol/deferred.d dsymbol/src/dsymbol/import_.d dsymbol/src/dsymbol/modulecache.d dsymbol/src/dsymbol/scope_.d dsymbol/src/dsymbol/semantic.d dsymbol/src/dsymbol/string_interning.d dsymbol/src/dsymbol/symbol.d dsymbol/src/dsymbol/tests.d dsymbol/src/dsymbol/type_lookup.d stdx-allocator/source/stdx/allocator/building_blocks/affix_allocator.d stdx-allocator/source/stdx/allocator/building_blocks/allocator_list.d stdx-allocator/source/stdx/allocator/building_blocks/bitmapped_block.d stdx-allocator/source/stdx/allocator/building_blocks/bucketizer.d stdx-allocator/source/stdx/allocator/building_blocks/fallback_allocator.d stdx-allocator/source/stdx/allocator/building_blocks/free_list.d stdx-allocator/source/stdx/allocator/building_blocks/free_tree.d stdx-allocator/source/stdx/allocator/building_blocks/kernighan_ritchie.d stdx-allocator/source/stdx/allocator/building_blocks/null_allocator.d stdx-allocator/source/stdx/allocator/building_blocks/package.d stdx-allocator/source/stdx/allocator/building_blocks/quantizer.d stdx-allocator/source/stdx/allocator/building_blocks/region.d stdx-allocator/source/stdx/allocator/building_blocks/scoped_allocator.d stdx-allocator/source/stdx/allocator/building_blocks/segregator.d stdx-allocator/source/stdx/allocator/building_blocks/stats_collector.d stdx-allocator/source/stdx/allocator/common.d stdx-allocator/source/stdx/allocator/gc_allocator.d stdx-allocator/source/stdx/allocator/internal.d stdx-allocator/source/stdx/allocator/mallocator.d stdx-allocator/source/stdx/allocator/mmap_allocator.d stdx-allocator/source/stdx/allocator/package.d stdx-allocator/source/stdx/allocator/showcase.d stdx-allocator/source/stdx/allocator/typed.d libdparse/src/dparse/ast.d libdparse/src/dparse/entities.d libdparse/src/dparse/lexer.d libdparse/src/dparse/parser.d libdparse/src/dparse/formatter.d libdparse/src/dparse/rollback_allocator.d libdparse/src/dparse/stack_buffer.d libdparse/src/std/experimental/lexer.d containers/src/containers/dynamicarray.d containers/src/containers/ttree.d containers/src/containers/unrolledlist.d containers/src/containers/openhashset.d containers/src/containers/hashset.d containers/src/containers/internal/hash.d containers/src/containers/internal/node.d containers/src/containers/internal/storage_type.d containers/src/containers/internal/element_type.d containers/src/containers/internal/backwards.d containers/src/containers/slist.d msgpack-d/src//msgpack/attribute.d msgpack-d/src//msgpack/buffer.d msgpack-d/src//msgpack/common.d msgpack-d/src//msgpack/exception.d msgpack-d/src//msgpack/package.d msgpack-d/src//msgpack/packer.d msgpack-d/src//msgpack/register.d msgpack-d/src//msgpack/streaming_unpacker.d msgpack-d/src//msgpack/unpacker.d msgpack-d/src//msgpack/value.d -Icontainers/src -Imsgpack-d/src -Ilibdparse/src -Idsymbol/src -Istdx-allocator/source -Jbin -wi -O -release -inline -ofbin/dcd-server

$ ./bin/dcd-server
2019-01-13T11:42:28.492:main.d:runServer:130 Starting up...
2019-01-13T11:42:28.493:main.d:runServer:164 Listening at /var/tmp/dcd-501.socket
2019-01-13T11:42:28.493:main.d:runServer:181 Import directories:

2019-01-13T11:42:28.493:main.d:runServer:187 0 symbols cached.
2019-01-13T11:42:28.493:main.d:runServer:188 Startup completed in 0 milliseconds.


# waits here for requests from the client


2019-01-13T11:43:00.678:main.d:runServer:171 Shutting down sockets...
2019-01-13T11:43:00.678:main.d:runServer:176 Sockets shut down.
std.socket.SocketOSException@std/socket.d(3185): Unable to set socket option: Invalid argument
----------------
??:? @trusted void std.socket.Socket.setOption(std.socket.SocketOptionLevel, std.socket.SocketOption, void[]) [0x1cb5b67]
??:? @trusted void std.socket.Socket.setOption(std.socket.SocketOptionLevel, std.socket.SocketOption, int) [0x1cb5ba8]
??:? @safe void std.socket.Socket.setSock(std.socket.socket_t) [0x1cb4aab]
??:? @trusted std.socket.Socket std.socket.Socket.accept() [0x1cb51aa]
??:? int dcd.server.main.runServer(immutable(char)[][]) [0x1b6d805]
??:? _Dmain [0x1ac83ef]

This is run in a separate terminal:

$ ./bin/dcd-client -I ~/.dvm/compilers/dmd-2.083.0/src/druntime/

jacob-carlborg avatar Jan 13 '19 10:01 jacob-carlborg

Since the problem is on the server side, reconnecting is not meaningful - we are only accepting connections from the client.

Yes, that doesn't make any sense.

So, the question is why would the client drop the connection immediately after connecting. Perhaps the IDE is killing the client process?

No IDE involved, just executing the client manually in the terminal.

jacob-carlborg avatar Jan 13 '19 10:01 jacob-carlborg