Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_STREAM_WRITE_AFTER_END #113

Closed
bitlab-code opened this issue Jan 9, 2019 · 9 comments
Closed

ERR_STREAM_WRITE_AFTER_END #113

bitlab-code opened this issue Jan 9, 2019 · 9 comments

Comments

@bitlab-code
Copy link

bitlab-code commented Jan 9, 2019

Hi,
if I run one request at a time everything works properly, but if I run two simultaneous requests the app crashed:
my app.js

import express from 'express';
import path from 'path';
import logger from 'morgan';
import bodyParser from 'body-parser';
import routes from './routes';
import fileUpload from 'express-fileupload';

const app = express();
app.disable('x-powered-by');

// View engine setup
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'pug');

app.use(logger('dev', {
  skip: () => app.get('env') === 'test'
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, '../public')));
app.use(express.static(path.join(__dirname, '../video/uploaded')));

app.use(fileUpload({
  limits: { fileSize: 50 * 1024 * 1024 },
  useTempFiles : true,
  tempFileDir : '/../../../video/temp/',
}));

// Routes
app.use('/', routes);

// Catch 404 and forward to error handler
app.use((req, res, next) => {
  console.log('-- Not Found --')
  const err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// Error handler
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
  console.log('-- ERROR --')
  res
    .status(err.status || 500)
    .render('error', {
      message: err.message
    });
});

export default app;

the log in console:

events.js:173
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:248:12)
    at WriteStream.Writable.write (_stream_writable.js:296:5)
    at FileStream.<anonymous> (/opt/bitnami/apps/ffmpeg/htdocs/node_modules/express-fileupload/lib/tempFileHandler.js:32:17)
    at FileStream.emit (events.js:188:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at FileStream.Readable.push (_stream_readable.js:224:10)
    at PartStream.onData (/opt/bitnami/apps/ffmpeg/htdocs/node_modules/busboy/lib/types/multipart.js:223:28)
    at PartStream.emit (events.js:188:13)
    at addChunk (_stream_readable.js:288:12)
Emitted 'error' event at:
    at errorOrDestroy (internal/streams/destroy.js:98:12)
    at writeAfterEnd (_stream_writable.js:250:3)
    at WriteStream.Writable.write (_stream_writable.js:296:5)
    [... lines matching original stack trace ...]
    at PartStream.emit (events.js:188:13)

edit:
this is error_log of apache:

[proxy_http:error] [pid 5083] (20014)Internal error (specific information not available): [client xxx.xx.xxx.x:52546] AH01102: error reading status line from remote server 127.0.0.1:3000
[proxy:error] [pid 5083] [client xxx.xx.xxx.x:52546] AH00898: Error reading from remote server returned by /upload

Any advice on how I can fix this?
Thanks

@RomanBurunkov
Copy link
Collaborator

I got the same error while uploading several files with a useTempFiles set to true.

Looks like useTempFiles feature not able to work with a several uploads at one time.

@RomanBurunkov
Copy link
Collaborator

@richardgirges Do you have any ideas, plans to resolve that?

@RomanBurunkov
Copy link
Collaborator

Well, I think I got the point, it is probably related to the following lines in tempfiles module:

`
tempFilePath = dir + 'tmp' + Date.now();
writeStream = fs.createWriteStream(tempFilePath);

`

Checking that...

@bitlab-code
Copy link
Author

@RomanBurunkov A month without answers... maybe the project is abandoned.
If you need to fix, take a look to this package: https://github.com/expressjs/multer

@richardgirges
Copy link
Owner

richardgirges commented Feb 6, 2019 via email

@RomanBurunkov
Copy link
Collaborator

@bitlab-code , probably you are right...

@richardgirges

My first suggestion that's not the issue...but may be in some cases it could be.

I suppose that problem in using one stream for several uploads.
It looks that tempfiles module use one stream closed in module for any upload, is that correct doing that?

I don't have a lot of experience with the streams, but I suppose that we should have different streams for several uploads in a one time.

@RomanBurunkov
Copy link
Collaborator

RomanBurunkov commented Feb 6, 2019

See my PR with fixing this issue.

#116

@RomanBurunkov
Copy link
Collaborator

Hi @richardgirges , have you had a chance to check this issue or/and my PR?

@richardgirges
Copy link
Owner

v1.1.1-alpha.2 has been published to NPM with @RomanBurunkov's fix.

https://github.com/richardgirges/express-fileupload/releases/tag/v1.1.1-alpha.2

Thanks @RomanBurunkov !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants