Skip to content

Commit

Permalink
Merge pull request #95 from envoy/fix-memory-leaks
Browse files Browse the repository at this point in the history
Fix memory leaks in HTTPConnection
  • Loading branch information
Goos authored Mar 28, 2021
2 parents 1f1fe7e + 9989790 commit 065b6ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/DefaultHTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class DefaultHTTPServer: HTTPServer {
logger: logger
)
connections.insert(connection)
connection.closedCallback = { [unowned self] in
connection.closedCallback = { [unowned self, unowned connection] in
self.connections.remove(connection)
}
logger.info("New connection \(connection.uuid) from [\(address)]:\(port)")
Expand Down
14 changes: 10 additions & 4 deletions Sources/HTTPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ public final class HTTPConnection {
self.eventLoop = eventLoop
self.closedCallback = closedCallback

transport.readDataCallback = handleDataReceived
transport.closedCallback = handleConnectionClosed
transport.readDataCallback = { [unowned self] data in
self.handleDataReceived(data)
}
transport.closedCallback = { [unowned self] reason in
self.handleConnectionClosed(reason)
}

let propagateHandler = PropagateLogHandler(logger: logger)
let contextHandler = TransformLogHandler(
handler: propagateHandler
) { [unowned self] record in
return record.overwriteMessage { [unowned self] in"[\(self.uuid)] \($0.message)" }
return record.overwriteMessage { [unowned self] in "[\(self.uuid)] \($0.message)" }
}
self.logger.add(handler: contextHandler)
}
Expand Down Expand Up @@ -133,7 +137,9 @@ public final class HTTPConnection {
// set SWSGI keys
environ["swsgi.version"] = "0.1"
environ["swsgi.url_scheme"] = "http"
environ["swsgi.input"] = swsgiInput
environ["swsgi.input"] = { [unowned self] (handler: ((Data) -> Void)?) in
self.swsgiInput(handler)
}
// TODO: add output file for error
environ["swsgi.error"] = ""
environ["swsgi.multithread"] = false
Expand Down

0 comments on commit 065b6ce

Please sign in to comment.