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

Should a terminate message be sent to the server on connection close()? #84

Closed
sqlisor opened this issue Feb 24, 2020 · 1 comment · Fixed by #86
Closed

Should a terminate message be sent to the server on connection close()? #84

sqlisor opened this issue Feb 24, 2020 · 1 comment · Fixed by #86
Labels
bug Something isn't working question Further information is requested

Comments

@sqlisor
Copy link

sqlisor commented Feb 24, 2020

Switching from libpq to postgres-nio, some of my unit tests failed because connections were still alive on the server after closing them on the client.
The connections only disappeared after closing the application.
This can be seen in pg_stat_activity
Sending a terminate message to the server in close() fixed the problem

public func close() -> EventLoopFuture<Void> {
    guard !self.didClose else {
        return self.eventLoop.makeSucceededFuture(())
    }    
    let _ = self.requestTerminate(logger: logger)
    ...
extension PostgresMessage {

    public struct Terminate: PostgresMessageType {
        
        public static var identifier: PostgresMessage.Identifier {
            return .terminate
        }
        
        public var description: String {
            return "Terminate"
        }
        
        public func serialize(into buffer: inout ByteBuffer) {
        }
    }
}

Is this a bug?

@tanner0101 tanner0101 added question Further information is requested bug Something isn't working labels Feb 26, 2020
@tanner0101
Copy link
Member

tanner0101 commented Feb 26, 2020

@sqlisor yeah this seems like a bug to me. MySQLNIO sends a close message to the server before closing the channel so we should follow suit here if that's also what Postgres wants.

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

Successfully merging a pull request may close this issue.

2 participants