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

If Unix domain socket file exists then Vapor crashes when starting instead of taking over the socket file #3085

Open
talmeme opened this issue Oct 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@talmeme
Copy link

talmeme commented Oct 13, 2023

Describe the bug

In the app's configure.swift, func configure(), set to use Unix domain socket (UDS):

app.http.server.configuration.address = .unixDomainSocket(path: unixDomainSocket)

If the UDS file exists then the app crashes upon start.

To Reproduce

  • Create an app to use UDS.
  • Start the app.
  • Verify that the app created the UDS in the specified path.
  • Kill the app so that it doesn't shut down cleanly.
  • Verify that the app's UDS still exists.
  • Start the app and see that it fails: bind(descriptor:ptr:bytes:): Address already in use (errno: 98) (Vapor/Application.swift:162)

Expected behavior

Vapor removes the old UDS file and recreates it. As per @gwynne on Discord, the bug is at https://github.com/vapor/vapor/blob/main/Sources/Vapor/HTTP/Server/HTTPServer.swift#L421:

channel = bootstrap.bind(unixDomainSocketPath: socketPath)

And the fix:

channel = bootstrap.bind(unixDomainSocketPath: socketPath, cleanupExistingSocketFile: true)

Tested working on my machine.

Environment

OS = Ubuntu 22.04 aarch64
Swift v5.9

    {
      "identity" : "vapor",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/vapor/vapor.git",
      "state" : {
        "revision" : "036d67e4da46126810f56c6a6ce813bcf259a745",
        "version" : "4.84.1"
      }
    },
@talmeme talmeme added the bug Something isn't working label Oct 13, 2023
@0xTim
Copy link
Member

0xTim commented Oct 24, 2023

@talmeme if you want to do a PR for this that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants