tmds / Tmds.Systemd

.NET Core library for interacting with systemd
Other
128 stars 17 forks source link

GetListenSockets throws InvalidOperationException on Accept #4

Closed logankp closed 7 years ago

logankp commented 7 years ago

When a socket is passed in via systemd I should be able to just call accept() on it, however I get an InvalidOperationException that states "You must call the Bind method before performing this operation."

tmds commented 7 years ago

@logankp Can you share the stack trace for the exception and the systemd unit file?

tmds commented 7 years ago

I will try to reproduce this. One question, I'm not sure why you are calling listen. I think systemd should call bind and listen; and you should call accept.

logankp commented 7 years ago

@tmds True, I meant accept(). I've updated the original comment.

Stack trace: Unhandled Exception: System.InvalidOperationException: You must call the Bind method before performing this operation. at System.Net.Sockets.Socket.Accept() at SocketService.Program.Main(String[] args)

I'm using systemd-socket-activate for testing: systemd-socket-activate -l 2000 dotnet /path/to/program.dll

tmds commented 7 years ago

@logankp can you try this using Version="0.2.0-*" from this myget feed:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="tmds" value="https://www.myget.org/F/tmds/api/v3/index.json" />
  </packageSources>
</configuration>
tmds commented 7 years ago

@logankp there is a test that checks this case

https://github.com/tmds/Tmds.Systemd/blob/03576707bfb3bf02f3fc95841fe7c1399bf9e39f/test/Tmds.Systemd.Tests/SocketTests.cs#L82-L91

It should work fine now. If you confirm it also works for you, we can close this issue.

logankp commented 7 years ago

Works great, thanks for all your hard work on this!

tmds commented 7 years ago

Great! No problem :) I'll push a new version to nuget.org tomorrow.