http2-push-example icon indicating copy to clipboard operation
http2-push-example copied to clipboard

No closeSync API called

Open xiabin1235910 opened this issue 8 years ago • 2 comments

I found in helper.js, we open the file to get the fileDescriptor using fs.openSync(filePath, 'r'). But do we need to close it when the server is closed?

the code in the node official API

server.on('close', () => fs.closeSync(fd));

The link is https://nodejs.org/dist/latest-v9.x/docs/api/http2.html#http2_http2stream_respondwithfd_fd_headers_options

xiabin1235910 avatar Nov 08 '17 10:11 xiabin1235910

like in helper.js

function closeFiles (baseDir) {
    ...
}

xiabin1235910 avatar Nov 08 '17 10:11 xiabin1235910

Sorry for the late response. In case you're still interested:

That could be a problem if we wrote to the files, or if we opened many different files for different endpoints and ran out of Unix sockets. Neither if the two happens in this.

This solution is a bit more efficient as we open the files when the server is fired up, so we can read the file contents straight away upon receiving a request. You are right, however, that it would be safer and nicer to only open the files when they are needed and close them once their content is sent.

Would you be up for opening a pull request to fix this?

Shadowbeetle avatar Apr 24 '18 11:04 Shadowbeetle