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
DicomServer does not close TCP connection #795
Comments
|
|
I found that just letting NetworkStream to keep reference to socket or TcpClient is not enough. DicomServer takes DicomService-derived class as type parameter. fo-dicom/DICOM/Network/DicomServer.cs Line 21 in c1abfb8
DicomService-derived class is instantiated by CreateScp. fo-dicom/DICOM/Network/DicomServer.cs Line 219 in c1abfb8
scp is assigned to local variable fo-dicom/DICOM/Network/DicomServer.cs Line 248 in c1abfb8
scp's RunAsync is invoked, and scp variable is just forgotten. fo-dicom/DICOM/Network/DicomServer.cs Line 254 in c1abfb8
this means that DicomService-derived class would only be disposed via finalizer. we have to make DicomServer to dispose instance of class T as well. |
DicomServer does not close TcpClient/socket after client closed connection.
reported by @cjcaldwell via gitter
Expected behavior
DicomServer closes TCP connection after client closed connection.
Actual behavior
DicomServer leaves TCP connection open after client closed connection.
Steps to reproduce the behavior
send C-ECHO request repeatedly to DicomServer and observe sockets.
see additional comments.
fo-dicom version and OS/platform
4.0.0
while DicomServer.Dispose() does not close TCP listen connection. #158 seems similar, network codes are getting evolved since then, this issue seems to be different one.
@cjcaldwell spotted that TcpClient does not get closed.
DesktopNetworkListener receives TcpClient into local variable.
fo-dicom/DICOM/Network/DesktopNetworkListener.cs
Line 71 in c1abfb8
TcpClient is passed to DesktopNetworkStream's constructor.
but DesktopNetworkStream does not store the reference.
fo-dicom/DICOM/Network/DesktopNetworkListener.cs
Line 82 in c1abfb8
now, no one has reference to the TcpClient.
TcpClient leaks without closing.
WindowsNetworkListener seems to be leaking socket in slightly different manner also.
WindowsNetworkListener passes new socket to WindowsNetworkStream's constructor.
fo-dicom/DICOM/Network/WindowsNetworkListener.cs
Line 115 in c1abfb8
WindowsNetworkStream's constructor stores the socket into member variable.
fo-dicom/DICOM/Network/WindowsNetworkStream.cs
Line 84 in c1abfb8
however, canDisposeSocket is set to false.
fo-dicom/DICOM/Network/WindowsNetworkStream.cs
Line 85 in c1abfb8
which makes socket leave open.
fo-dicom/DICOM/Network/WindowsNetworkStream.cs
Line 144 in c1abfb8
now socket leaks without closing.
comment on DesktopNetworkListener's constructor says that closing TcpClient is caller's responsibility.
fo-dicom/DICOM/Network/DesktopNetworkStream.cs
Line 80 in c1abfb8
probably it was at the moment the comment was written, but it is suspicious now.
WindowsNetworkStream's constructor also has similar comment.
fo-dicom/DICOM/Network/WindowsNetworkStream.cs
Line 74 in c1abfb8
thank you again to @cjcaldwell
The text was updated successfully, but these errors were encountered: