summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-02-13 17:41:39 +0100
committerJames M Snell <jasnell@gmail.com>2018-02-16 13:54:14 -0800
commitcbe6d5c5198d649e59b97382d69dc5f52a2c5e74 (patch)
tree3b6cc261a5129f32d0fb558cb7a088b88ab84c25 /doc
parent755d805bf471423631fb8320b223298c88a61969 (diff)
downloadandroid-node-v8-cbe6d5c5198d649e59b97382d69dc5f52a2c5e74.tar.gz
android-node-v8-cbe6d5c5198d649e59b97382d69dc5f52a2c5e74.tar.bz2
android-node-v8-cbe6d5c5198d649e59b97382d69dc5f52a2c5e74.zip
doc: warn against concurrent http2stream.respondWithFD
Upcoming changes to move away from synchronous I/O on the main thread will imply that using the same file descriptor to respond on multiple HTTP/2 streams at the same time is invalid, because at least on Windows `uv_fs_read()` is race-y. Therefore, warn against such usage. PR-URL: https://github.com/nodejs/node/pull/18762 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/http2.md19
1 files changed, 13 insertions, 6 deletions
diff --git a/doc/api/http2.md b/doc/api/http2.md
index 6dc9946118..66cf7aafa0 100644
--- a/doc/api/http2.md
+++ b/doc/api/http2.md
@@ -1257,10 +1257,10 @@ automatically.
const http2 = require('http2');
const fs = require('fs');
-const fd = fs.openSync('/some/file', 'r');
-
const server = http2.createServer();
server.on('stream', (stream) => {
+ const fd = fs.openSync('/some/file', 'r');
+
const stat = fs.fstatSync(fd);
const headers = {
'content-length': stat.size,
@@ -1268,8 +1268,8 @@ server.on('stream', (stream) => {
'content-type': 'text/plain'
};
stream.respondWithFD(fd, headers);
+ stream.on('close', () => fs.closeSync(fd));
});
-server.on('close', () => fs.closeSync(fd));
```
The optional `options.statCheck` function may be specified to give user code
@@ -1282,6 +1282,12 @@ The `offset` and `length` options may be used to limit the response to a
specific range subset. This can be used, for instance, to support HTTP Range
requests.
+The file descriptor is not closed when the stream is closed, so it will need
+to be closed manually once it is no longer needed.
+Note that using the same file descriptor concurrently for multiple streams
+is not supported and may result in data loss. Re-using a file descriptor
+after a stream has finished is supported.
+
When set, the `options.getTrailers()` function is called immediately after
queuing the last chunk of payload data to be sent. The callback is passed a
single object (with a `null` prototype) that the listener may use to specify
@@ -1291,10 +1297,10 @@ the trailing header fields to send to the peer.
const http2 = require('http2');
const fs = require('fs');
-const fd = fs.openSync('/some/file', 'r');
-
const server = http2.createServer();
server.on('stream', (stream) => {
+ const fd = fs.openSync('/some/file', 'r');
+
const stat = fs.fstatSync(fd);
const headers = {
'content-length': stat.size,
@@ -1306,8 +1312,9 @@ server.on('stream', (stream) => {
trailers.ABC = 'some value to send';
}
});
+
+ stream.on('close', () => fs.closeSync(fd));
});
-server.on('close', () => fs.closeSync(fd));
```
The HTTP/1 specification forbids trailers from containing HTTP/2 pseudo-header