Calling server.closeConnections()
or server.close(true)
prevents stats collection
#555
Labels
t-platform
Issues with this label are in the ownership of the platform team.
validated
Issues that are resolved and their solutions fulfill the acceptance criteria.
I’m using
proxy-chain
to monitor proxy traffic consumption, but I noticed that I was undercounting the number of transmitted bytes.Before starting to use the proxy, I register a listener on the
connectionClosed
event like this:After finishing with the proxy, I call
server.close(true)
. However, when theconnectionClosed
events are fired, thestats
are alwaysundefined
.Upon investigating the implementation of
server.close()
, I found that it callsserver.closeConnections()
when the first parameter istrue
.The issue appears to be caused by this line in
server.ts
, line 636:Unlike the
closeConnection(connectionId: number)
method just above in the same file, this function clears thethis.connections
map. I’m not sure why this line was added, or if removing it has any negative side effects, but typically each entry in this map is removed by the socket's close event listener, as seen inserver.registerConnection()
line 215:It’s critical that
this.connections
is modified afterserver.getConnectionStats()
is called:In summary, calling
server.closeConnections()
orserver.close(true)
prevents stats collection by clearingthis.connections
beforeserver.getConnectionStats()
can retrieve the necessary information.Workaround
Currently, I avoid the issue by manually closing connections like this:
Proposed Fix
I suggest removing this line in
server.ts
. If this solution is acceptable, I can submit a pull request with the fix. What do you think?The text was updated successfully, but these errors were encountered: