Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set socket option: Invalid argument #345

Open
jacob-carlborg opened this issue Aug 17, 2016 · 4 comments
Open

Unable to set socket option: Invalid argument #345

jacob-carlborg opened this issue Aug 17, 2016 · 4 comments

Comments

@jacob-carlborg
Copy link
Contributor

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 (1037406), using DMD v2.071.1. I'm running on OS X. It seems like using TCP socket instead of Unix socket works.

@jacob-carlborg
Copy link
Contributor Author

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] zeromq/libzmq#1442
[3] zeromq/libzmq@ceb6be7

@CyberShadow
Copy link
Member

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?

@jacob-carlborg
Copy link
Contributor Author

Just compiled with git master at 144cc4e:

$ 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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants