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

Socket.io : Could not load session for socket #....... #2263

Closed
billyshena opened this issue Sep 26, 2014 · 20 comments
Closed

Socket.io : Could not load session for socket #....... #2263

billyshena opened this issue Sep 26, 2014 · 20 comments
Assignees

Comments

@billyshena
Copy link

Hello everyone. I've been working with sails 0.10.2 version and sometimes when I quit my browser and restart it to hit my app url , I get an error like this:

error: Could not load session for socket #F4O-lvWICcs6uQTYREOc
error: The socket's cookie could not be parsed into a sessionID.
error: Unless you're overriding the authorization function, make sure you pass in a valid sails.sid cookie
error: (or omit the cookie altogether to have a new session created and an encrypted cookie sent in the response header to your socket.io upgrade request)
error: TypeError: Cannot call method 'indexOf' of undefined
at exports.parseSignedCookie (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/node_modules/express/node_modules/connect/lib/utils.js:199:19)
at Object.Session.fromSocket (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/lib/hooks/session/index.js:339:38)
at interpretSocketReq (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/lib/hooks/sockets/lib/interpreter/interpret.js:542:19)
at Socket. (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/lib/hooks/sockets/lib/connection.js:95:5)
at Socket.emit as $emit
at SocketNamespace.handlePacket (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/node_modules/socket.io/lib/namespace.js:335:22)
at Manager.onClientMessage (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/node_modules/socket.io/lib/manager.js:518:38)
at WebSocket.Transport.onMessage (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/node_modules/socket.io/lib/transport.js:369:20)
at Parser. (/Users/bshen/Desktop/educloud-v20/backend/node_modules/sails/node_modules/socket.io/lib/transports/websocket/hybi-16.js:39:10)
at Parser.emit (events.js:95:17) [TypeError: Cannot call method 'indexOf' of undefined]

I've tried to debug but can't figure out what's wrong. Any kind of request to my Sails API launches this error and I have to make a refresh/F5 on my browser to make it work again.

Does anyone have an idea?
Regards,

@timestep
Copy link
Contributor

@billyshena
Copy link
Author

Ok the issue is a conflict of cookies => I've been using http://luisfarzati.github.io/angulartics/ to install Google Analytics with my angularjs application. For each request / call to my Sails js API, the cookie sent with the socket and the one sent by angulartics (for google analytics) somehow "come in conflict" and my SailsJS server prints this error.
I think Sails is getting the cookie sent by Google analytics first (which is not valid to Sails server) and prints out this error which stops the process.

Is there any workaround for this issue?
Regards

@billyshena
Copy link
Author

After some testing on my side, I could reproduce exactly the issue doing the following steps and the bug appears on one condition:

  1. I close my browser + empty my cache
  2. If I go on my http://localhost:8080 again, => socket ERROR appears => Could not load session for socket #....
  3. If I refresh (F5) => everything works again

Conflict appears to be with Google analytics cookies and Sails socket cookie

@macedd
Copy link

macedd commented Nov 29, 2014

Very weird behavior (if has to do with analytics)

Can a core dev give us any insights?

@macedd
Copy link

macedd commented Nov 29, 2014

The problem is clearly addressed in this (thread)[http://stackoverflow.com/questions/21106983/unable-to-get-session-for-socket-in-sailsjs-after-restart].
Sockets can`t recreate the session, so a Jsonp request should be done before starting the io.

This feature could be implemented in sailsSocket with a failover.

@macedd
Copy link

macedd commented Nov 29, 2014

To workaround the browser/socket/cookie problem just call the backend with an ajax call

# at console
$.get(window.io.sails.url)

But I have no idea of how to detect the problem and automate the workaround for socket-only apps

@billyshena
Copy link
Author

thiagof: I'm using $sailsSocket and not ajax calls mhhh. However, this issue also appears with other websites cookie stored.

@macedd
Copy link

macedd commented Nov 30, 2014

The ajax call is to restore your session with the backend, cause
socket calls do not make it.
But the workaround is for fixing development environment.
Production deploys can suffer from the problem someday...

2014-11-29 20:46 GMT-02:00, billyshena notifications@github.com:

thiagof: I'm using $sailsSocket and not ajax calls mhhh. However, this issue
also appears with other websites cookie stored.


Reply to this email directly or view it on GitHub:
#2263 (comment)

Thiago Fernandes
Analista de Processos
34 9176- 4055 | thiago@internetbudi.com.br

@billyshena
Copy link
Author

Mhh so no real fixes at moment then. Looks like other sails user do not have this issue

@RobiFerentz
Copy link

👍
Have this issue too, currently.

@svnh
Copy link

svnh commented Dec 11, 2014

+1

@billyshena
Copy link
Author

Did anyone find out a solution or any fix?

@stensrud
Copy link

+1

1 similar comment
@ghost
Copy link

ghost commented Feb 17, 2015

+1

@macedd
Copy link

macedd commented Feb 18, 2015

Have you tried to enable session storage?

2015-02-17 19:13 GMT-02:00 GeoCloud notifications@github.com:

+1


Reply to this email directly or view it on GitHub
#2263 (comment).

Thiago Fernandes
Analista de Processos
34 9176- 4055 | thiago@internetbudi.com.br

@JetFault
Copy link

JetFault commented Mar 9, 2015

I'm getting the same thing. I overwrote my socket.js authorization to use my own logic. And according to the error message, that's one way to remove this issue, but that doesn't seem to be the case.

I'm wondering is there a way to turn off sessions in general (I'm using JWT). I've disabled the cookieParser middleware, but now want to also disable all sessions in generale.

@mikermcneil
Copy link
Member

Sorry for the slow response guys.

@JetFault re: disabling session- you can do so by disabling the session hook. As of Sails 0.11, the sockets hook should fully support session-free usage.

@stenstrud @RobiFerentz @svnh @billyshena have you been able to reproduce this in Sails v0.11 w/ the new sockets hook?

@mackenrou
Copy link

Hi @mikermcneil
I updated to sails 0.11 disabling the session hook and fix this, but now socket don't connect on android browser and phonegap app as i explained here: #2874

@macedd
Copy link

macedd commented Apr 27, 2015

Best solution to me were using a database session adapter

2015-04-27 11:09 GMT-03:00 mackenrou notifications@github.com:

Hi @mikermcneil https://github.com/mikermcneil
I updated to sails 0.11 disabling the session hook and fix this, but now
socket don't connect on android browser and phonegap app as i explained
here: #2874 #2874


Reply to this email directly or view it on GitHub
#2263 (comment).

Thiago Fernandes
Analista de Processos
34 9176- 4055 | thiago@internetbudi.com.br

@mikermcneil
Copy link
Member

Thanks for posting, @billyshena. I'm a repo bot-- nice to meet you!

It has been 60 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

  • review our contribution guide to make sure this submission meets our criteria (only verified bugs with documented features, please; no questions, commentary, or bug reports about undocumented features or unofficial plugins)
  • create a new issue with the latest information, including updated version details with error messages, failing tests, and a link back to the original issue. This allows GitHub to automatically create a back-reference for future visitors arriving from search engines.

Thanks so much for your help!

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

No branches or pull requests

9 participants