Bug 6737 - Socket.Close(int) doesn't linger
Summary: Socket.Close(int) doesn't linger
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-08-29 11:02 UTC by Jonathan Pryor
Modified: 2014-07-29 07:16 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Jonathan Pryor 2012-08-29 11:02:10 UTC
Context: http://mono-for-android.1047100.n5.nabble.com/Linger-no-effect-tt5711630.html

Wanted: actual test case.

Socket.Close(int) allows a "timeout" value to be provided:

http://msdn.microsoft.com/en-us/library/bc68k4td.aspx

The problem is that the timeout isn't actually used, because we never linger. Following the code, the client calls Socket.Close(int):

https://github.com/mono/mono/blob/2e7acd75/mcs/class/System/System.Net.Sockets/Socket_2_1.cs#L1235

Socket.Close(int) sets linger_timeout, then calls Dispose():

https://github.com/mono/mono/blob/2e7acd75/mcs/class/System/System.Net.Sockets/Socket_2_1.cs#L1215

Which calls Dispose(bool):

https://github.com/mono/mono/blob/2e7acd75/mcs/class/System/System.Net.Sockets/Socket_2_1.cs#L1189

Dispose(bool) sets connected=false (line 1196), then calls Linger(IntPtr):

https://github.com/mono/mono/blob/2e7acd75/mcs/class/System/System.Net.Sockets/Socket_2_1.cs#L1158

The first thing Linger() does?

	if (!connected || linger_timeout <= 0)
		return;

Dispose(bool) just set connected=false, therefore !connected is true, therefore we immediately return without lingering at all.

Oops.

This is obviously broken. I'm not immediately sure how to fix it, and I don't want to fix it until we have a proper test case for this scenario.

Note You need to log in before you can comment on or make changes to this bug.