vti / mojox-session

Session management for Mojo
Other
15 stars 10 forks source link

Event "read" failed for connection "IO::Socket::INET=GLOB(0xb61738)" #4

Closed tomiles closed 14 years ago

tomiles commented 14 years ago

I know that you won't improve it or extend. But can't get the couchdb store to work I always get:

Event "read" failed for connection "IO::Socket::INET=GLOB(0xb61738)": Wrong response at /opt/local/lib/perl5/site_perl/5.8.9/Mojo/Client.pm line 630

and in my couchdb log I see the put request that creates the session document return a 500 error but I don't know why.

'PUT'   /session/ff310c54325a3c54e4fac1a8379682fba9114ba8   500

Could you help? and if not, do you know how I could use couchdb with the embedded Mojolicious sessions instead?

vti commented 14 years ago

It says that CouchDB returned 500 response, instead of 200 or 201. Try doing this using another software. Like embedded CouchDB client. Maybe the problem is in version compatibility.

Speaking about embedded sessions... What data do you store in CouchDB? Is it just a few kb? Then you don't need a store at all. With embedded sessions cookies are signed in order to be sure that they weren't changed when your app last edited it. It is much faster since you don't need a separate request and is a lot easier to use.

tomiles commented 14 years ago

I store extended information about a dynamic javascript page, so that on page refresh some of the dynamic stuff can be reload from the session data and the state of the page can be restored. My CouchDB server is working fine I can put and get info from the DB with other client, so it must be an issue with the PUT data that Couchdb.pm sends.

vti commented 14 years ago

Why don't you use then JavaScript CouchDB clients?

Could you show me how you use MojoX::Session so I can replicate the bug?

tomiles commented 14 years ago

Ok i put in some croaks so I could take a look at the data it send to couchdb. And there is the issue it sends: { "logged_in": "false", "expires": 1274120830, "__ip_match": "127.0.0.1" }

but in CouchDB __ip_match is not allowed, because names starting with underscores are not allowed in the root level of a document that is reserved for internal variables like _rev, _id ... So a fix would be to save __ip_match inside another level like:

{
   "logged_in": "false",
   "expires": 1274120830,
   "data": { "__ip_match": "127.0.0.1"}
}
tomiles commented 14 years ago

I use Javascript Couchdb client but the Mojo scripts also need access to the session data because the html page state has to be coupled to the session of the current user.

vti commented 14 years ago

Ah, that's a very interesting bug :) That was a temporary idea to hide private data from a user.

tomiles commented 14 years ago

Underscore names at root level have always been reserved in couch but it could be that it didn't show up earlier if you used and older couchdb version, because a few versions back couchdb didn't enforce the underscore rule, but it does now.

tomiles commented 14 years ago

Will there be a new cpan release with a fix for this? or should I just uninstall the cpan module and use a patched version on my local server myself?

vti commented 14 years ago

Do you think it is a good idea to replace __ip_address with mojox.session.ip_address?

tomiles commented 14 years ago

as far as I know it's only couchdb that is having issues with the underscores so you could just change: $data = $self->_encode_json({%$data, expires => $expires}); to $data = $self->_encode_json({data => %$data, expires => $expires}); in the couchdb load and create methods and then adapt the load method so it again puts everything under 'data =>' at the same level in the $body that is returned.

mojox.session.ip_address will be a pain in perl because of the special meaning of points in perl, when the json encoding is translated to perl variables/hash.

vti commented 14 years ago

I've updated git version. Could you try it and report the results? If everything is ok I will release it on CPAN.

Thanks

tomiles commented 14 years ago

Just gave it a go and the couchdb stuff seems to work fine now. Thanks for the fix

tomiles commented 14 years ago

Fixed in latest github source and MojoX-Session-0.20 on CPAN. Closing the issue.