I have implemented a file server in Javascript using the hyco-https server, and when I create a file read stream for the fetched file and pipe it to the hyco ServerResponse object, the transfer stalls before the entire file has been streamed.
It appears that the first chunk is being written to the ServerResponse object via the streams write() method, but that subsequent writes do not occur. The hyco implementation of the streams write() function appears to always return false, but then never issues the 'drain' event to restart writes.
As a simple test, I modified the _writeRaw() method of the hyco OutgoingMessage object to always return true rather than false (_hyco_outgoing.js, line 321), and that "fixed" the problem. This change, of course, doesn't take into account the stream's interaction with the hyco Websocket, but it seems to demonstrate that the issue I am observing is a result of streams flow control.
Here's test code that behaves the same way as my fileserver, which I tested with a 100Kb jpg image (this server works fine if I substitute the standard nodejs http library for hyco-https and access the server directly):
// only interested in images and raw bytes (defaults to plain text below)
const mimeType = {
'.jpg': 'image/jpeg',
'.dat': 'application/octet-stream'
};
const uri = hycoHttp.createRelayListenUri(relayNamespace, relayPath);
// To run without hyco-https, uncomment the following line and comment out the following nine lines
// const server = http.createServer(
const server = hycoHttp.createRelayedServer(
{
server: uri,
token: () => {
console.debug('token refresh');
var relayToken = hycoHttp.createRelayToken(uri, saPolicy, saKey, TOKEN_TIMEOUT_SEC);
return relayToken;
}
},
function (req, res) {
console.log('GET ' + req.url);
console.log('Fileserver listening on port ' + port);
## Expected Behavior
1. The `ServerResponse` object should allow streaming via the nodejs streams interface.
## Versions
- OS platform and version: MacOS 10.14.6 and Docker `node:lts`
- Node Version: 12.9.1 and 12.13 (docker)
- NPM package version or commit ID: hyco-https 1.4.1
Actual Behavior
hyco-https
server, and when I create a file read stream for the fetched file and pipe it to the hycoServerResponse
object, the transfer stalls before the entire file has been streamed.ServerResponse
object via the streamswrite()
method, but that subsequent writes do not occur. The hyco implementation of the streamswrite()
function appears to always returnfalse
, but then never issues the'drain'
event to restart writes._writeRaw()
method of the hycoOutgoingMessage
object to always returntrue
rather thanfalse
(_hyco_outgoing.js
, line 321), and that "fixed" the problem. This change, of course, doesn't take into account the stream's interaction with the hyco Websocket, but it seems to demonstrate that the issue I am observing is a result of streams flow control.http
library forhyco-https
and access the server directly):// only interested in images and raw bytes (defaults to plain text below) const mimeType = { '.jpg': 'image/jpeg', '.dat': 'application/octet-stream' };
const relayNamespace = process.env.RELAY_NAMESPACE || ''; const relayPath = process.env.RELAY_PATH || ''; const saPolicy = process.env.RELAY_SA_POLICY_NAME || ''; const saKey = process.env.RELAY_SA_POLICY_KEY || '';
const TOKEN_TIMEOUT_SEC = 3000;
const hycoPath = '/test';
const uri = hycoHttp.createRelayListenUri(relayNamespace, relayPath);
// To run without hyco-https, uncomment the following line and comment out the following nine lines // const server = http.createServer( const server = hycoHttp.createRelayedServer( { server: uri, token: () => { console.debug('token refresh'); var relayToken = hycoHttp.createRelayToken(uri, saPolicy, saKey, TOKEN_TIMEOUT_SEC); return relayToken; } }, function (req, res) { console.log('GET ' + req.url);
); server.listen(parseInt(port));
console.log('Fileserver listening on port ' + port);