Skip to content

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

@sqlisor

Description

@sqlisor

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions