Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Issue 2760293002: [dart:io] Adds a finalizer to _NativeSocket to avoid socket leaks (Closed)

Created:
3 years, 9 months ago by zra
Modified:
3 years, 8 months ago
Reviewers:
Cutch, siva, kevmoo
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

[dart:io] Adds a finalizer to _NativeSocket to avoid socket leaks The finalizer sends the "close" message to the EventHandler for the file descriptor in the _NativeSocket's native field. To avoid races and spurious messages, this CL stores a pointer to a wrapper object in the native field instead of the file descriptor. All messsages about the _NativeSocket sent to the EventHandler use the wrapper object instead of the file descriptor. When the EventHandler closes the file, the file descriptor in the wrapper object is set to -1 so that the finalizer will instead do nothing. On Windows, there is another level of indirection since the OS HANDLEs were already wrapped in various kinds of Handle objects. As an additional complication, ClientSocket close on Windows is asynchronous, so the EventHandler may shutdown before all of the ClientSocket Handles can be destroyed. related #27898, #28081 R=johnmccutchan@google.com Committed: https://github.com/dart-lang/sdk/commit/89dba57bcf6b5c6a28f9adee4b3f86195f64f6ae

Patch Set 1 #

Patch Set 2 : Cleanup #

Patch Set 3 : Add test #

Patch Set 4 : Windows fixes #

Patch Set 5 : Properly reuse Sockets where needed #

Patch Set 6 : Windows fixes #

Patch Set 7 : Fix templates #

Patch Set 8 : Fix mac build #

Patch Set 9 : Fix Android and Fuchsia builds #

Patch Set 10 : Add asserts #

Total comments: 7

Patch Set 11 : Add comments. Drain Windows IO completion port in Debug #

Total comments: 4

Patch Set 12 : Address comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+563 lines, -174 lines) Patch
M runtime/bin/error_exit.cc View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M runtime/bin/eventhandler.h View 1 chunk +2 lines, -0 lines 0 comments Download
M runtime/bin/eventhandler.cc View 2 chunks +16 lines, -7 lines 0 comments Download
M runtime/bin/eventhandler_android.cc View 1 2 3 4 5 6 7 8 9 3 chunks +10 lines, -3 lines 0 comments Download
M runtime/bin/eventhandler_fuchsia.cc View 1 2 3 4 5 6 7 8 9 4 chunks +10 lines, -2 lines 0 comments Download
M runtime/bin/eventhandler_linux.cc View 1 2 3 4 5 6 3 chunks +10 lines, -4 lines 0 comments Download
M runtime/bin/eventhandler_macos.cc View 1 2 3 4 5 6 7 8 9 3 chunks +10 lines, -3 lines 0 comments Download
M runtime/bin/eventhandler_win.h View 1 2 3 4 5 6 7 8 9 10 10 chunks +31 lines, -11 lines 0 comments Download
M runtime/bin/eventhandler_win.cc View 1 2 3 4 5 6 7 8 9 10 11 15 chunks +135 lines, -40 lines 0 comments Download
M runtime/bin/main.cc View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +2 lines, -0 lines 0 comments Download
M runtime/bin/process.h View 1 2 3 4 5 2 chunks +3 lines, -1 line 0 comments Download
M runtime/bin/process.cc View 1 2 3 4 5 3 chunks +25 lines, -10 lines 0 comments Download
M runtime/bin/process_win.cc View 1 2 3 4 5 6 7 8 9 10 3 chunks +11 lines, -2 lines 0 comments Download
M runtime/bin/reference_counting.h View 1 2 3 4 5 6 1 chunk +28 lines, -6 lines 0 comments Download
M runtime/bin/socket.h View 1 2 3 4 9 chunks +38 lines, -12 lines 0 comments Download
M runtime/bin/socket.cc View 1 2 3 4 5 6 7 8 9 10 39 chunks +132 lines, -68 lines 0 comments Download
M runtime/bin/socket_android.cc View 1 2 3 4 5 6 7 8 1 chunk +9 lines, -0 lines 0 comments Download
M runtime/bin/socket_fuchsia.cc View 1 2 3 4 5 6 7 8 1 chunk +9 lines, -0 lines 0 comments Download
M runtime/bin/socket_linux.cc View 1 2 3 4 5 6 1 chunk +9 lines, -0 lines 0 comments Download
M runtime/bin/socket_macos.cc View 1 2 3 4 5 6 7 1 chunk +9 lines, -0 lines 0 comments Download
M runtime/bin/socket_win.cc View 1 2 3 4 5 6 chunks +22 lines, -5 lines 0 comments Download
M tests/standalone/io/socket_bind_test.dart View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +2 lines, -0 lines 0 comments Download
A tests/standalone/io/socket_finalizer_test.dart View 1 2 3 1 chunk +39 lines, -0 lines 0 comments Download

Messages

Total messages: 13 (6 generated)
zra
Self review https://codereview.chromium.org/2760293002/diff/180001/runtime/bin/eventhandler_win.cc File runtime/bin/eventhandler_win.cc (right): https://codereview.chromium.org/2760293002/diff/180001/runtime/bin/eventhandler_win.cc#newcode144 runtime/bin/eventhandler_win.cc:144: Retain(); // A reference to the Handle ...
3 years, 9 months ago (2017-03-25 22:39:50 UTC) #1
zra
3 years, 9 months ago (2017-03-26 22:36:30 UTC) #4
kevmoo
DBQ: does this fix a known issue? There were a few hanging around that sound ...
3 years, 9 months ago (2017-03-27 01:05:05 UTC) #6
zra
On 2017/03/27 01:05:05, kevmoo wrote: > DBQ: does this fix a known issue? > > ...
3 years, 9 months ago (2017-03-27 02:23:35 UTC) #8
Cutch
LGTM w/minor comments https://codereview.chromium.org/2760293002/diff/200001/runtime/bin/eventhandler_win.cc File runtime/bin/eventhandler_win.cc (right): https://codereview.chromium.org/2760293002/diff/200001/runtime/bin/eventhandler_win.cc#newcode594 runtime/bin/eventhandler_win.cc:594: AcceptEx_ = NULL; Maybe a note ...
3 years, 9 months ago (2017-03-27 17:17:50 UTC) #9
zra
https://codereview.chromium.org/2760293002/diff/200001/runtime/bin/eventhandler_win.cc File runtime/bin/eventhandler_win.cc (right): https://codereview.chromium.org/2760293002/diff/200001/runtime/bin/eventhandler_win.cc#newcode594 runtime/bin/eventhandler_win.cc:594: AcceptEx_ = NULL; On 2017/03/27 17:17:50, Cutch wrote: > ...
3 years, 8 months ago (2017-03-28 14:40:19 UTC) #11
zra
3 years, 8 months ago (2017-03-28 14:44:11 UTC) #13
Message was sent while issue was closed.
Committed patchset #12 (id:220001) manually as
89dba57bcf6b5c6a28f9adee4b3f86195f64f6ae (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698