If Unix domain socket file exists then Vapor crashes when starting instead of taking over the socket file
talmeme opened this issue · 1 comments
talmeme commented
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"
}
},