The web in a box - a next generation web framework for the Perl programming language

IRC log for #mojo, 2017-04-19

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
00:35 pink_mist sri: https://rt.cpan.org/Public/Bug/Display.html?id=112309 \resolved/ \released/
00:57 Lee joined #mojo
02:09 noganex joined #mojo
02:26 vicash hello. while using websockets with Mojo, is there a way to check why the websocket close code is 1006 ?
02:54 chandwki I'm building an API and I want to authenticate the user using a google account. I'm looking at these instructions, https://developers.google.com/identity/sign-in/web/backend-auth
02:54 chandwki so I have the id_token from google when I sign in but I need to verify that token on the backend
02:54 chandwki but I'm having a hell of a time figuring out which module I need to do that
02:55 chandwki the example in the documentation is only for nodejs, php, java, and python
02:58 vicash chandwki: use Mojolicious::Plugin::Web::Auth for Google. I use it and it works well
03:02 chandwki see, this is where I am confused
03:02 purl You won't be after this episode of Soap!
03:03 chandwki that module implies that the user already has an access key to their account or something
03:03 chandwki I already have the id_token from the javascript call that I wan't to verify
03:03 chandwki does that make sense?
03:24 chandwki oh, nvm
03:24 chandwki read the documentation further, I can just verify the id_token with this endpoint https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
03:31 maschine bpmedley, what do you mean by "unlimit"?
03:31 bpmedley maschine : Sorry, typo: possibly "ulimit"
03:47 maschine yeah sorry I still don't know what that is. lol
03:50 maschine reading about it now
03:50 maschine not really sure, it seemed to work fine for a while but now it crashes after only a couple jobs are run
04:04 dboehmer joined #mojo
04:11 maschine I think I figured it out - for some reason, a hot restart of hypnotoad is causing some sort of memory leak.  Probably something I've screwed up
04:12 maschine I ran 'ps --sort -rss -eo rss,pid,command | head' and there there like 6 hypnotoad PIDs running with my app
04:12 maschine I noticed recently, and it's probably something to do with my nginx config or security - that nginx gives me an internal error the first time I try a hot restart of hypnotoad
04:13 maschine like the process runs and everything, but I get 500 internal error when I connect over http
04:13 maschine if I just run hypnotoad again, it works.
04:16 maschine btw bpmedley thanks for the idea, a search on that lead me to the answer :)
04:19 purl1 joined #mojo
04:19 purl joined #mojo
04:54 kiwiroy joined #mojo
05:24 Janos joined #mojo
05:33 purl joined #mojo
05:39 inokenty-w joined #mojo
05:44 bwf joined #mojo
06:11 janl joined #mojo
06:27 karjala_ joined #mojo
06:35 [0xAF] joined #mojo
06:42 prg joined #mojo
07:14 AndrewIsh joined #mojo
07:24 trone joined #mojo
07:27 Vandal joined #mojo
07:35 kes joined #mojo
07:54 ashimema joined #mojo
08:17 rshadow joined #mojo
08:23 nic Grinnz: That looks perfect.  thanks
08:33 osfabibisi joined #mojo
08:44 [0xAF] I'm doing mysql inserts from a websocket onmessage handler. I'm using Mojo::mysql->db->query() for that. I want to handle the cases where the unique keys already exist (or any other mysql error). Unfortunately, I cannot find the right way to do it. I always get 'Mojo::Reactor::Poll: I/O watcher failed: DBD::mysql::st execute failed: Duplicate entry...'. Any idea how to handle that mysql errors. I need ot
08:44 [0xAF] catch the error and send a message through the websocket, informing the user.
08:48 salva joined #mojo
09:02 [0xAF] after a small patch here: https://github.com/jhthorsen/mojo-mysql/blob/master/lib/Mojo/mysql/Database.pm#L58   I can provide my own errorhandler (similar to the CB) and this solves my problem. The Carp is not caller, so the execution in my onmessage handler continues and I can use the Mojo::mysql::Results->errstr to pass the error to the websocket
09:03 [0xAF] batman: perhaps you could think of a nice way to give the user of (Mojo::mysql) the ability to provide his own error handler.
09:03 [0xAF] or perhaps I can learn how to use the module better?!?
09:06 kiwiroy joined #mojo
09:09 Peppard joined #mojo
09:56 kwa [0xAF]: You need to use Perl to handle your errors. Using eval {} or something like p3rl.org/Try::Tiny - I wouldn't say it was the responsibility of a database abstraction layer to provide error handling like that.
10:00 kwa If you're expecting duplicate keys, you could check if there's a duplicate before inserting. It's an extra call, but *shrugs*
10:01 kwa If you used a proper database like Postgres, you could use ON CONFLICT. INSERT INTO foo(id, name) (1, 'kwa') ON CONFLICT (id) DO NOTHING;
10:03 CHYC [0xAF]: ON DUPLICATE KEY ..... ? https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
10:28 nic lol
10:28 nic mysql had that LONG before pg
10:30 nic kwa: I'm not seeing how you could get eval to work for async
10:32 kwa nic: Ah, I missed the async part. :set ignorememode
10:36 [0xAF] kwa: I've tried with eval, but no luck. Your suggestion on Postgres is reasonable. But still I believe, I should be able to catch the errors, whatever they are.
10:38 [0xAF] CHYC: yeah, I know about that, but in this case, I prefer to send a message to the user, instead of presuming what the user would need (update or no-insert)
10:40 [0xAF] and doing an extra select is not a solution actually, it's more like workaround, but let's say i import milions of rows from CSV ... doing extra work is not good...
10:41 kwa [0xAF]: Hmm. Actually, I'm not sure what nic meant about async. The synopsis in Mojo::mysql shows the use of eval. I would have thought it possible to trap the error, and ignore or reraise based on the exception.
10:41 nic [0xAF]: Now it doesn't sound like you're in the a suitable domain for Mojo::mysql
10:41 nic As soon as you start doing industrial db work, you revert to an industrial handler (DBD::mysql)
10:42 [0xAF] nic: yesh, i've expected to work with eval, but i guess, since i'm in websocket and my handler is called from event, this makes it async and the error i see does not come from mysql module or any of my modules, it comes from: Mojo::Reactor::Poll
10:43 pink_mist [0xAF]: just set a handler for the error event - $mysql->on(error => sub { my ($mysql, $error) = @_; ... });
10:44 kwa Ah of course. Mojo::mysql inherits from Mojo::EventEmitter.
10:44 [0xAF] pink_mist: hm, I didnt knew about that, thanks for the suggestion. But please have a look in the update routine of Mojo::mysql::Database, at this line https://github.com/jhthorsen/mojo-mysql/blob/master/lib/Mojo/mysql/Database.pm#L58
10:44 [0xAF] local $sth->{HandleError} = sub { $_[0] = Carp::shortmess($_[0]); 0 };
10:44 pink_mist that's for blocking
10:45 [0xAF] it seems explicitly overriden
10:45 [0xAF] it's the same for non-blocking
10:45 [0xAF] (look ar line 66)
10:46 [0xAF] i guess i need to learn more about Mojo::EventEmitter, it seems i misunderstand it...
10:46 pink_mist what do you mean "the same for non-blockin"?
10:46 pink_mist +g
10:47 [0xAF] at line 66 where the non-blocking call of update routine is setup, the error handler is set to err => Carp::shortmess('__MSG__')
10:47 janl left #mojo
10:47 [0xAF] i guess the Carp will break the execution again, like in the blocking call of update
10:50 pink_mist [0xAF]: bullshit, that's just a setting on the object. any error would be passed to your callback though. ... it seems ->on(error => ... might not be the right way to do it anyway though, because if you look at https://metacpan.org/pod/Mojo::mysql::Database#query you see it says it passes in any error it gets to the callback as second parameter... so if you're using it async, that's already being passed
10:50 pink_mist in for you.
10:52 [0xAF] pink_mist: yeah, you're right about the non-blocking call, and now i remember that i considered that earlier... unfortunatelly i did not tried it, since i prefered to stay in the blocking call
10:52 pink_mist if you're doing it blocking, use eval
10:52 pink_mist kwa already told you
10:52 pink_mist and nic said it was only for blocking
10:53 itaipu joined #mojo
10:53 dod joined #mojo
10:53 [0xAF] pink_mist: eval does not work, for unknown to me reason... i was expecting it to work... but Mojo::Reactor::Poll still halts the execution
10:54 [0xAF] perhaps i should make more experiments, i could have it wrongly setup?!? thought what could be wrong to eval something...
10:54 pink_mist fine, try the ->on(error => ... then
10:54 [0xAF] pink_mist: yeah, that sounds promissing, thank you very much for the idea...
11:00 dod joined #mojo
11:06 [0xAF] unfortunatelly the ->on(error=>...) does not work either...
11:07 [0xAF] this Carp there which is set to the $sth->{HandleError} is the problem ... and i guess it never comes to the Mojo::EventEmitter...
11:12 kwa [0xAF]: Have you seen this: https://github.com/jhthorsen/mojo-mysql/blob/02590daff8c8cff9f96a8595b20623e3aae83e2c/t/database.t#L104-L119 ?
11:14 [0xAF] kwa: not exactly this, thanks for the link. it seems I should really consider calling it non-blocking, like in the example. so i can catch the error
11:15 [0xAF] kwa: i just want to make some more experiments with eval first... i should be working as far as i understand
11:15 kwa It indicates that you should be able to trap the error if you're calling it blocking.
11:16 kwa Indeed. Where are you executing your $msql->db->query() stuff from?
11:16 [0xAF] kwa: i'm sure it i should be able... just cant unserstand why it did not worked.
11:17 [0xAF] kwa: it's an onmessage handler of websocket
11:18 kwa [0xAF]: That's javascript to me? Right? (ws.onmessage = function() { ... }
11:19 [0xAF] kwa: javascript ws.onmessage is on the client side... on the server side is $ws->on('message' => sub...), or actually it's $ws->on('json'...) which is the same as message
11:19 kwa Or is it in mojo $c->on(message => sub { ... })?
11:20 [0xAF] and i'm crappy stupid....
11:20 [0xAF] i've made a million stupid things to solve a problem which does not exist!!!
11:20 [0xAF] the eval is working just fine ....
11:21 [0xAF] i dunno why it did not worked in first place, or what had i done to make it now work...
11:21 tchaves joined #mojo
11:21 [0xAF] but it was the first thing to try and i just gave up after the first try and started to look for a problem that does no exist
11:21 [0xAF] stupid me...
11:22 [0xAF] i'm so angry on me right now (and embarrassed)... sorry for taking your time guys...
11:25 rshadow joined #mojo
11:26 [0xAF] i'm almost 100% sure that i did not checked $@ after the eval, but something else perhaps .... how stupid...
11:29 * [0xAF] is going back to the hole of oblivion and embarrassment... I vow not to talk to any developer for the next week, out of my stupidity...
11:31 nic When you make an everyday error it's important to keep talking & talking about it so that it becomes an epic
11:35 [0xAF] joined #mojo
11:35 [0xAF] sorry, but i was (and still am) so angry on me, that i forgot to say:
11:35 [0xAF] Thank you all, for the help and your time.
11:35 [0xAF] It's much appriciated!
11:37 stryx` joined #mojo
11:53 karjala_ joined #mojo
12:09 kiwiroy joined #mojo
12:13 itaipu joined #mojo
12:26 osfabibi_ joined #mojo
12:40 osfabibisi joined #mojo
13:16 bwf joined #mojo
13:31 Janos joined #mojo
13:42 * nic wonders whether [0xAF] is still angry
13:58 maschine heh too hard on himself.  Dumb mistakes are the seeds of learning. :p
14:17 mib_jstpge joined #mojo
14:20 gizmomathboy joined #mojo
14:24 maschine in the minion plugin documentation: http://mojolicious.org/perldoc/Mojolicious/Plugin/Minion
14:24 maschine it says $app->minion->perform_jobs; is for testing?  not meant for production use?
14:25 maschine so far for prototyping I've been running "perl ./myapp.pl minion worker" to run my job queue, but obviously leaving an SSH shell running on a machine somewhere can't be done permanently
14:31 nic have you checked how many workers are currently running?
14:31 vicash maschine: use screen to launch the minion worker so you dont need to leave a shell open
14:32 jberger or better, start a service with whatever init system your OS provides
14:32 nic screen is wonderful, but I wouldn't use it for that purpose
14:33 jberger so I have a thing I can't believe I haven't stumbled on yet
14:33 jberger we have respond_to for when the client wants one of several types
14:33 maschine jberger, so essentially I would create a service with "perl ./myapp.pl minion worker" that would run on startup?
14:34 jberger but do we have anything for when the client SENDS us one of several types?
14:34 jberger maschine: yes
14:34 jberger maschine: also note the -j option for handling multiple jobs at once
14:34 * nic is disappointed.  Was sure Joel's 'thing' was going to entail a medical description
14:36 nic jberger: Have you hit a scenario that normal routing can't cope with?
14:37 maschine I think I need to do basically the same thing to run hypnotoad on startup anyway
14:38 jberger maschine: yes, likely similar, though hypnotoad usually needs a different switch to tell it that it is going to prefork
14:39 jberger nic: so when writing slack integrations (yes, my company is going to slack-for-doing-stuff) some of the hooks send urlencoded data and some send json
14:39 jberger but they always include a token to check that it is a legitimate request
14:39 jberger and I want to check this in an under
14:39 jberger so the question is, do I just try to decode as json and if it fails use param
14:40 jberger or do I check the content_type (with a regexp because I don't care about charset)
14:40 jberger and it strikes me that it would be handy to have something like reply_to but is instead for the request not the reply
14:40 pink_mist reply_for?
14:41 nic I see
14:41 pink_mist (just naming suggestion, not something I think exists already :P)
14:48 jberger anyway, it seems like an obvious thing to want now, but I'm surprised I haven't wanted it before
14:48 jberger which makes me think that perhaps it isn't very useful, despite the fact that it SEEMS like it would be useful now
15:07 maschine joined #mojo
15:19 batman jberger: how do you know what the client sends?
15:19 dod joined #mojo
15:29 maschine ok I give up.  I can't find the command line options for hypnotoad.  I don't think -f is for preforking?
15:31 maschine ok I found it (I never really give up) http://mojolicious.org/perldoc/hypnotoad
15:32 maschine Looks like i have to do it in the config instead of the command line?
15:35 bwf joined #mojo
15:35 jberger maschine, what are you doing?
15:35 jberger -f is to keep it in the foreground
15:35 jberger but you don't want that
15:36 jberger what OS are you on
15:36 jberger ?
15:36 jberger there is a deployment example for systemd
15:37 jberger http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#Hypnotoad
15:37 jberger at the bottom of that section
15:38 maschine ubuntu
15:40 maschine -f was just a guess :p
15:47 jberger recent ubuntus are systemd
15:47 jberger just steal that
15:50 mishanti1 joined #mojo
15:56 disputin joined #mojo
15:59 jberger nic / others: this is what I came up with: https://gist.github.com/jberger/3191e551d3f21d71f495e7de4c130ad0
16:00 Pyritic joined #mojo
16:01 jberger maybe it is over-pedantic to have any and none, but it was just a quick thing
16:01 jberger and actually, for what I'm doing I think I'm not even going to use it
16:01 jberger but it was worth a gist at least
16:04 jberger batman: sorry, I didn't see you post
16:04 jberger for this case I know from the request content type header
16:04 jberger but presumably you could do it with trying to parse the body as json or other such tests
16:09 PryMar56 joined #mojo
16:31 Janos joined #mojo
16:37 itaipu joined #mojo
16:37 sh14 joined #mojo
16:45 stryx` joined #mojo
17:07 jesk what content-type should I chose when I want to emulate the beahvior of curl with --data-binary posting?
17:08 jesk or better to ask for the right way to use useragent for that in general
17:09 Grinnz to post binary data to the server?
17:09 jesk want to post data to prometheus
17:10 Grinnz you would set the content type header to application/octet-stream, probably
17:10 jesk the examples from promentheus use things like this:  echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.ex
17:11 Grinnz and pass the content as normal, with no charset
17:12 Grinnz (last argument to ->post)
17:13 jesk I'am struggling how I could post large multline string via mojo useragent this way
17:13 jesk blocking would be fine
17:15 Grinnz just all as one string, otherwise you'd need to use https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Streaming-request
17:15 Grinnz to do it piecemeal
17:15 jesk can you give me an example?
17:16 Grinnz $ua->post($url, {'Content-Type' => 'application/octet-stream'}, $data);
17:16 jesk nice let me try
17:18 jesk can I just leave it by that or should I need to parse/close anything after that?
17:18 jesk prometheus won't give anything big tho
17:19 jesk s,big,back,
17:19 Grinnz you get the normal $tx as return value, with the response
17:20 Grinnz check $tx->result for response, it will die on connection errors
17:20 Grinnz https://metacpan.org/pod/Mojo::Transaction#result
17:20 jesk ok
17:41 jesk thanks, works like a charm!
17:48 kiwiroy joined #mojo
18:07 tchaves joined #mojo
18:10 kiwiroy joined #mojo
18:32 castaway joined #mojo
18:41 kiwiroy joined #mojo
18:48 itaipu joined #mojo
19:09 kiwiroy joined #mojo
19:16 chandwki joined #mojo
20:01 kiwiroy joined #mojo
20:19 punter joined #mojo
20:37 vicash Hello. When creating a Websocket in javascript is the sub-protocol necessary ? I just use "var ws = new WebSocket(url)" and it closes with code 1006 every time it receives a single message from the server.
20:38 jberger some services require a subprotocol
20:38 jberger but generally it isn't required
20:38 vicash This was not happening in another run that was using Mojolicious 6.0 and now on upgrading to the latest, the websocket closes
20:38 vicash the javascript code is the same, albeit the browser is also more recent.
20:39 vicash how do I debug this ?
20:39 preaction what is the response the Mojolicious is sending back?
20:39 jberger MOJO_WEBSOCKET_DEBUG=1
20:39 jberger or else MOJO_DAEMON_DEBUG=1
20:39 preaction iirc there's a pre-flight check like CORS
20:39 jberger depending on the level you want to look at
20:40 vicash thanks i will try it out. I don't think CORS is the problem as I am not switching domains.. all testing is within a LAN and directly with a Mojolicious server rather than with a reverse proxy in the middle
20:40 jberger if the socket is closing with 1006 then the preflight and handshake succeeded
20:40 jberger vicash: does your reverse proxy handle websockets
20:41 jberger you need a relatively new Apache or Nginx
20:41 vicash ok. yes the server sends a simple message and the client receives it and then the server says websocket closed with 1006.
20:41 vicash jberger: yes i use Nginx but for testing right now I am not using it.
20:41 jberger vicash: which application server are you using?
20:42 vicash jberger: browser is firefox, and the web application is written with Mojolicious. the unit tests use Test::Mojo and work perfectly.
20:42 vicash there is no other application
20:42 jberger hypnotoad? morbo? starman?
20:42 vicash jberger: morbo. sorry i was confused by application server
20:42 jberger daemon?
20:42 purl well, daemon is forever or http://www.libslack.org/daemon/
20:43 jberger ok
20:43 jberger making sure you were using a mojo server
20:43 jberger vicash: can you make a minimal example?
20:43 vicash anyway, i will try out the MOJO_WEBSOCKET_DEBUG soon and see what comes out. from what I know the 1006 is caused because the browser closes the socket.
20:44 vicash jberger: yes let me try doing that and seeing if that works
20:44 jberger oh, did you watch the browser console for messages?
20:45 jberger and even, I have a guess ...
20:45 jberger I'm guessing https:// vs ws://
20:45 jberger chrome hates that
20:48 vicash jberger: yes. i am logging all messages to console to see what is happening. I am using http:// and ws:// because this is running in development mode
20:48 jberger but you don't see anything in particular in the console log?
20:49 vicash jberger: no nothing in console log. only in the Mojolicious logs I see the 1006 message. My code is based on the chat with websocket example of Mojolicious
20:50 vicash jberger: maybe i will try that out directly and see
20:52 dikim joined #mojo
20:56 vicash jberger: the chat example works fine. I am going to modify my code to use EventEmitter to send messages and see if that helps
21:30 dantti_laptop joined #mojo
21:34 jberger vicash: do you have a strong reference to the transaction?
21:34 jberger if not then the transaction is closed when it goes out of scope
21:35 jberger in the initial websocket connect add my $tx = $c->tx;
21:35 jberger and then add $c->on(finish => sub { undef $tx });
21:48 kiwiroy joined #mojo
22:02 sri Grinnz: haha, i started playing overwatch on a new account and climbing is soooo much easier, it's ridiculous
22:03 sri now platinum, close to getting diamond
22:09 sri the new heroes are not bad
22:57 kiwiroy joined #mojo
23:36 vicash jberger: i will try that out.
23:53 vicash jberger: the problem was not in my perl code but my javascript code. i was doing some unnecessary page reloading when the websocket received a null message. turning that off makes it work as expected. thanks

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary