question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem after updating from 2.0.2 to 2.0.3 with middleware

See original GitHub issue

This error occurred the first time after updating from 2.0.2 to 2.0.3 - I really can’t figure it out right now.

/data/project/app/node_modules/on-headers/index.js:25
	throw new TypeError('argument res is required')
	^

TypeError: argument res is required
	at onHeaders (/data/project/app/node_modules/on-headers/index.js:25:11)
	at session (/data/project/app/node_modules/express-session/index.js:219:5)
	at Array.<anonymous> (/data/project/app/modules/webserver.js:41:5)
	at run (/data/project/app/node_modules/socket.io/lib/namespace.js:123:11)
	at Namespace.run (/data/project/app/node_modules/socket.io/lib/namespace.js:135:3)
	at Namespace.add (/data/project/app/node_modules/socket.io/lib/namespace.js:163:8)
	at Client.connect (/data/project/app/node_modules/socket.io/lib/client.js:76:20)
	at Server.onconnection (/data/project/app/node_modules/socket.io/lib/index.js:398:10)
	at emitOne (events.js:115:13)
	at Server.emit (events.js:210:7)
error: Forever detected script exited with code: 1
error: Script restart attempt #63
const session = require('express-session');
[..]
const httpsServer = https.createServer(credentials, app).listen(config.server.port);
const io = require('socket.io')(httpsServer);

var sessionMiddleware = session({
    store: new RedisStore({}),
    secret: 'MYSECRET',
    resave: false,
    saveUninitialized: true
});

io.use(function (socket, next) {
    sessionMiddleware(socket.request, socket.request.res, next); //(/data/project/app/modules/webserver.js:41:5)
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
ToddAlvordcommented, Aug 30, 2017

I found that this works. sessionMiddleware( socket.request, {}, next );

You will have access to your session via socket.request.session. The res part is used to notify the session handler to check if it should save the session data or not after a request has completed. I never could get session data to save automatically with socket.io, even in v1. If you need to make changes to your session in a socket.io connection you can use socket.request.session.save(). Basically remove the res part as it wasn’t being used anyways by socket.io. At least not in a way that seems to have any affect.

1reaction
akontsevichcommented, Dec 5, 2018

@ToddAlvord thanks for the solution! Think it could be improved a little:

io.use(function(socket, next) {
    sessionMiddleware(socket.request, socket.request.res || {}, next);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Oracle Application Server 10g Release 2 (10.1.2) Support ...
2 bug fixes. However, the patchset will not add any new functionality that 10.1.2.0.2 contains. The Database Patchset 10.1.0.4.2 is a minimal ...
Read more >
Update your security processor (TPM) firmware
Learn how to update your security processor or TPM firmware to protect Windows 10 and your device from attacks by malicious software.
Read more >
IBM Content Navigator, Version 2.0.3 Fix Pack 2 Readme
This readme document contains information about installation and removal of the fix pack and about known problems, restrictions, ...
Read more >
http-proxy-middleware - npm
The one-liner node.js proxy middleware for connect, express and browser-sync. Latest version: 2.0.6, last published: 8 months ago.
Read more >
Changes — Flask Documentation (2.2.x)
Update Werkzeug dependency to >= 2.2.2. This includes fixes related to the new faster router, header parsing, and the development server.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found