Skip to content

Commit 971ec87

Browse files
jclulowianlancetaylor
authored andcommitted
runtime: check for events when port_getn fails with ETIME
On illumos systems, and at least historically on Solaris systems, it is possible for port_getn(3C) calls to return some number of events and then fail with error ETIME. Generally we expect this to happen if the caller passes an nget value larger than 1 and calls with a timeout; if less than the requested number of events accumulate the system will still return them after timeout failure so the caller must check the updated nget value in the ETIME case. Note that although less likely this can still happen even when requesting just 1 event, especially with a short timeout value or on a busy system. Fixes #35261 Change-Id: I0d83251b69a2fadc64c4e8e280aa596e2e1548ba Reviewed-on: https://go-review.googlesource.com/c/go/+/204801 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
1 parent 1e4a358 commit 971ec87

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/runtime/netpoll_solaris.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,21 @@ func netpoll(delay int64) gList {
229229
var events [128]portevent
230230
retry:
231231
var n uint32 = 1
232-
if port_getn(portfd, &events[0], uint32(len(events)), &n, wait) < 0 {
233-
if e := errno(); e != _EINTR && e != _ETIME {
232+
r := port_getn(portfd, &events[0], uint32(len(events)), &n, wait)
233+
e := errno()
234+
if r < 0 && e == _ETIME && n > 0 {
235+
// As per port_getn(3C), an ETIME failure does not preclude the
236+
// delivery of some number of events. Treat a timeout failure
237+
// with delivered events as a success.
238+
r = 0
239+
}
240+
if r < 0 {
241+
if e != _EINTR && e != _ETIME {
234242
print("runtime: port_getn on fd ", portfd, " failed (errno=", e, ")\n")
235243
throw("runtime: netpoll failed")
236244
}
237-
// If a timed sleep was interrupted, just return to
238-
// recalculate how long we should sleep now.
245+
// If a timed sleep was interrupted and there are no events,
246+
// just return to recalculate how long we should sleep now.
239247
if delay > 0 {
240248
return gList{}
241249
}

0 commit comments

Comments
 (0)