net: setKeepAlive() ignores the error returned by the handle
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- cpp, javascript, nodejs
- Bereich
- networking
Rechercherichtung
Beginne mit dem Pfad socket.setKeepAlive() und TCPWrap::SetKeepAlive in src/tcp_wrap.cc und reproduziere dann den Fall mit negativer Verzögerung aus dem Issue. Vergleiche die Behandlung mit setTypeOfService() und untersuche das für macOS und andere Systeme festgestellte Plattformverhalten. Als abgeschlossen gilt die Arbeit, wenn zugrunde liegende Fehler nicht mehr stillschweigend verworfen werden und das vom Team genehmigte Fehlerverhalten verwendet wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Version
v27.0.0-pre (main)
Platform
Darwin 25.4.0 arm64
Subsystem
net
What steps will reproduce the bug?
const net = require('net');
const server = net.createServer().listen(0, () => {
const socket = net.connect(server.address().port, () => {
// Looks like it succeeded
const returned = socket.setKeepAlive(true, -5000);
console.log('returns socket:', returned === socket);
// The handle actually returned EINVAL
const err = socket._handle.setKeepAlive(true, -5, 1, 10);
console.log('handle returns:', err);
socket.destroy();
server.close();
});
});
Output:
returns socket: true
handle returns: -22
How often does it reproduce? Is there a required condition?
Every time, for any value the platform rejects.
What is the expected behavior? Why is that the expected behavior?
socket.setKeepAlive() should not report success when the underlying
operation failed. setTypeOfService(), right next to it in the same file,
already does this:
const err = this._handle.setTypeOfService(tos);
if (err && !isWindows) {
throw new ErrnoException(err, 'setTypeOfService');
}
What do you see instead?
setKeepAlive() discards the return value of the handle call:
this._handle.setKeepAlive(enable, initialDelay, interval, count);
TCPWrap::SetKeepAlive does propagate the error to JS
(args.GetReturnValue().Set(err) in src/tcp_wrap.cc), and
uv_tcp_keepalive_ex() returns UV_EINVAL for a negative delay, so the
information is available. It is simply dropped.
The caller has no way to tell: the return value is the socket either way,
and no error is thrown or emitted.
Additional information
Found while working on #57712 / #65528, which adds a warning for delays
below 1000 ms that are truncated to 0. That change is about values which
are silently reduced; this one is about an error which is silently
discarded, so it seemed better to report it separately.
I have not checked how a value above the platform limit behaves on other
systems. On macOS setKeepAlive(true, 40000000) (40000 s) is accepted by
the handle, so any range check would need per-platform investigation first.
I am happy to open a PR if the direction is agreed. Whether a failure
should throw, like setTypeOfService(), or only emit a warning is a
decision I would rather leave to the team, since throwing would be a
breaking change.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.4k
- Ø Merge
- 4 T. 3 Std.
- Gemergte PRs (30 T.)
- 279
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nodejs/node
-
doc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
build
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
feature request
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Ähnliche Issues
-
bug confirmed issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
open-webui/open-webui#30750 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Mend: dependency security vulnerability untriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100