ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.23.1 | Fund Crystal's development: | GH: | Docs: | API: | Gitter:
bcardiff has joined #crystal-lang
bcardiff has quit [Quit: bcardiff]
<FromGitter> <elorest> has anyone expirienced an issue where context.response.headers don’t all end up in the headers from curl or the browser. Sort of sporatically.
bcardiff has joined #crystal-lang
w-p has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
rohitpaulk has joined #crystal-lang
<bmcginty> Anyone here have issues detecting closed sockets? I'm trying to check to see if a persistent connection is still alive, and I can't figure out when/what is supposed to be returned when the remote end of a socket closes.
<bmcginty> elorest: I was seeing weird http stuff last week...weird enough that I'm trying to write/use my own to figure out what was going on. Though mine has just been in the client.
<FromGitter> <elorest> k
renich has quit [Quit: Renich]
http_GK1wmSU has joined #crystal-lang
bcardiff has quit [Quit: bcardiff]
http_GK1wmSU has left #crystal-lang [#crystal-lang]
Philpax has joined #crystal-lang
<oprypin> elorest, hopefully you aren't putting broken strings with arbitrary bytes in there?
hightower has joined #crystal-lang
tosmi` has joined #crystal-lang
tosmi has quit [Ping timeout: 260 seconds]
hightower has quit [Ping timeout: 240 seconds]
<FromGitter> <konovod> .
<FromGitter> <elorest> <oprypin> Nope.
<FromGitter> <sdogruyol> Good morning everyone
<FromGitter> <elorest> Morning.
<FromGitter> <elorest> <oprypin> For some reason if the body is even moderately large(~200 elements) it changes to chunked mode and overwrites the existing headers with ⏎ ⏎ ```< HTTP/1.1 200 OK ⏎ < Connection: keep-alive ⏎ < Transfer-Encoding: chunked``` []
<FromGitter> <elorest> If I reduce the size of the http body all of my headers get sent.
<FromGitter> <elorest> And my cookies get set in my browser.
<shelvacu> Is it a consistent size that changes it? Maybe 4k bytes or something?
<FromGitter> <elorest> Working one with smaller body. ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <elorest> Same url.
<FromGitter> <elorest> I’ll try to find the content lenght where it breaks.
<shelvacu> Do you have some code that reliably reproduces it?
<FromGitter> <elorest> Yes.
<shelvacu> You should definitely file a bug report.
<shelvacu> Or post the code here so I can file such a report
<FromGitter> <elorest> `Content-Length: 8191` works but one more character in the body and it goes to chunked and doesn’t send headers.
<shelvacu> seems the most likely culprit but I don't see how that would cause any problems.
<shelvacu> deflate compression lib and stdlib buffered io both use a buffer size of 8192
<shelvacu> 1
<FromGitter> <elorest> Yeah I’m finding stuff about that number everywhere. As far as html pages are concerned it’s not really that big.
<FromGitter> <elorest> I believe that chunking after that size is appropriate. I just tested a couple rails sites. They also chuck after that number but they don’t delete my headers in the process.
snsei has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
snsei has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
mark_66 has joined #crystal-lang
snsei has joined #crystal-lang
<bmcginty> oprypin: It's with sockets that I'm having the issue. Straight reading from them times out (while checking to see if .read returns 0).
snsei has quit [Remote host closed the connection]
rohitpaulk has quit [Ping timeout: 255 seconds]
snsei has joined #crystal-lang
http_GK1wmSU has joined #crystal-lang
snsei has quit [Remote host closed the connection]
http_GK1wmSU has left #crystal-lang [#crystal-lang]
<FromGitter> <bararchy> bmcginty: Can you share a code exmaple ?
early has quit [Quit: Leaving]
early has joined #crystal-lang
<oprypin> bmcginty, no difference
<oprypin> sockets when explicitly closed will get you 0. but detecting remote socket going away is not reliable, hence timeout
<bmcginty> oprypin: thanks.
hightower has joined #crystal-lang
trapped has joined #crystal-lang
trapped has quit [Read error: Connection reset by peer]
trapped has joined #crystal-lang
bmcginty has quit [Ping timeout: 248 seconds]
bmcginty has joined #crystal-lang
<FromGitter> <code-andres> Hi, everyone... I'm stuck using concurrency for a simple logger... ⏎ ⏎ I have a Process, a spawn where the output is print and i want to use another spawn where each 3 seconds for example, kill the old Process and send the new one to the first spawn, I was trying with channels but the spawn must wait for a send. ⏎ ⏎ In littler words, is there a way to create just a "listener"between spawns
<FromGitter> <bararchy> Buffered Channel maybe ?
<FromGitter> <crisward> Can anyone explain to me what this does ⏎ ⏎ ```Signal::PIPE.trap do ⏎ # some code ⏎ end``` []
<FromGitter> <akzhan> This is signal handler. They interrupts process execution for some events.
<FromGitter> <akzhan> Many operating systems allow signals to be sent to running processes. Some signals have a defined effect on the process, while others may be trapped at the code level and acted upon. For example, your process may trap the USR1 signal and use it to toggle debugging, and may use TERM to initiate a controlled shutdown.
<FromGitter> <akzhan> this is citation from Ruby doc :)
<FromGitter> <akzhan> And usually should to set ignore on PIPE signal.
http_GK1wmSU has joined #crystal-lang
http_GK1wmSU has left #crystal-lang [#crystal-lang]
tosmi` has quit [Ping timeout: 260 seconds]
<FromGitter> <crisward> @akzhan Thanks... I was using this around a `socket.send` as I was getting application crashes when the remote end disconnected mid message. However it seems to stop the sockets sending altogether. I can't remember what the exception was.
<FromGitter> <crisward> I think someone on here suggested it, I added it a while ago, but just realised it's actually preventing the sockets being sent.
DTZUZO has quit [Ping timeout: 255 seconds]
<oprypin> crisward, putting code inside signal.trap doesn't mean wrapping it, the code actually won't run. the code will run when the corresponding signal is received
<oprypin> so the suggestion to use that probably meant something different
<FromGitter> <crisward> oprypin - so it's like a rescue on begin, rescue ? Should I therefore just do this once globally ? Or once before every socket.send ? Perhaps I'll take a look at the ruby docs.
<oprypin> once globally
<oprypin> not yet released docs
<FromGitter> <crisward> @oprypin Thanks! Never thought of looking in the docs on master.
w-p has quit [Ping timeout: 260 seconds]
<oprypin> well sure, there's almost never a reason for that
rohitpaulk has joined #crystal-lang
bcardiff has joined #crystal-lang
bcardiff has quit [Ping timeout: 246 seconds]
greengriminal has joined #crystal-lang
greengriminal has quit [Remote host closed the connection]
greengriminal has joined #crystal-lang
DTZUZO has joined #crystal-lang
snsei has joined #crystal-lang
bcardiff has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
alex`` has joined #crystal-lang
sz0 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
alibby has quit [Ping timeout: 260 seconds]
alibby has joined #crystal-lang
_helloworld_ has joined #crystal-lang
_helloworld_ has quit [Quit: Page closed]
snsei has quit [Remote host closed the connection]
greengriminal has quit [Quit: Leaving]
<RX14> i got a segfault in the compiler while investigating a segfault in a program
<RX14> which is nice
snsei has joined #crystal-lang
Philpax has quit [Ping timeout: 260 seconds]
mark_66 has quit [Remote host closed the connection]
vegai has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<RX14> my segfault disappears under gdb :ok_hand:
<RX14> so somehow this generated code is ignoring the calling conventions and overwriting rbx
<RX14> ok so it's stack corruption
<RX14> damnit
<oprypin> sounds pleasant
bcardiff has quit [Ping timeout: 240 seconds]
bcardiff has joined #crystal-lang
<RX14> oprypin, read man 3 accept and tell me i'm crazy to think that using out here is completely wrong:
<RX14> man page says you should allocate struct sockaddr*
<RX14> and have a pointerof the size
<RX14> which the kernel sets the pointer to the used size
<RX14> but here it's just using "out" which makes no sense right
<oprypin> RX14, so basically they're passing 0 as address_len
<oprypin> but it is indeed also an out parameter
<RX14> no they're passing uninitialized stack as address_len
<RX14> right?
<oprypin> mm not sure but probably right
<RX14> there's no guarantees that an out param will be initialized to 0
<oprypin> ok
<RX14> i think at least
<RX14> i would assume given llvm that that's a thing
renich has joined #crystal-lang
<oprypin> RX14, ok but let's say this problem is there, wouldn't that problem be ignored in terms of stack validity?
<RX14> no because the sockaddr* is on the stack too
<RX14> pass the wrong size and the kernel will overwrite your stack
<oprypin> ok
<RX14> neither of them are used anyway
<oprypin> so the stack validity fails indirectly due to buffer overflow
<RX14> it's kind of a buffer overflow
<RX14> because we just told the kernel essentially
renich has quit [Remote host closed the connection]
<RX14> "use a random number for the size of this buffer"
<RX14> and it did
<RX14> and the buffer was on the stack
<RX14> this might all be BS
<RX14> because i don't know what i'm doing
renich has joined #crystal-lang
<oprypin> theoretically it's possible that this input is not even used because why wouldnt the function know sizeof(sockaddr)
<oprypin> i think the function writes min(addrlen, sizeof(sockaddr)) bytes so no buffer overflow
<RX14> no because sockaddr* is an array
<RX14> i think
<RX14> idk
<oprypin> lol C amirite
<RX14> i'm wrong oprypin
<RX14> its worse
<RX14> sockaddr can be different structs
<RX14> thats whyn it has a length option
<crystal-gh> [crystal] konovod opened pull request #4787: Added Float32 and Float64 consts (master...float_consts)
<oprypin> just change it to nil nil and be done with it
<RX14> yes oprypin
<RX14> i just tested it
<RX14> and it fixes it
<oprypin> :)
<RX14> but i'm still wondering how the fuck it ever worked in the first place
<oprypin> > <‎oprypin‎>‎ i think the function writes min(addrlen, sizeof(sockaddr)) bytes so no buffer overflow
<RX14> no but
<RX14> if it breaks in release mode now
<RX14> the line blames to 8 months ago
<RX14> how on earth has this not been caught before
<oprypin> wut
<RX14> this has been broken for 8 months
<oprypin> broken in very specific scenarios maybe
<RX14> it's in the critical path for HTTP servers
<RX14> lol
<RX14> how on earth has this not been tested to hell
<oprypin> because in most scenarios it happened to be 0 or something
<RX14> yes but i'm still amazed
<RX14> this was broken before
renich has quit [Read error: Connection reset by peer]
<RX14> longer than 8 months
renich has joined #crystal-lang
<RX14> ysbaddaden just refactored and brought the bug with it
<RX14> do you know what's really janky about blame? Try to find out who authored a line of code which is being *deleted* in a diff
<oprypin> there are probably other ways like searching every revision for it
<RX14> yes but i typically git blame on github
<RX14> i probably shouldn't complain then
<RX14> oprypin, jan 2015
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
<Yxhuvud> RX14: vc-region-history in emacs. gives all history for the selected region. totally amazeballs function
<Yxhuvud> (assuming modern enough emacs)
<RX14> Yxhuvud, doesn't really work for this case
<Yxhuvud> should do, unless the refactoring was huge (or the line was in some other file or some totally other place)
<RX14> yes the latter
<RX14> the refactoring was huge AND across files
<RX14> i need to go blame -> diff
<RX14> which is easy
<RX14> and then i need to find where it was deleted and blame there
<RX14> which is hard on github
<RX14> because you can't go from a deleted line in a diff to blame
<Yxhuvud> yeah, stuff like that is easier from the command line.
<RX14> its actually not
<RX14> using magit i can use git-blame-micro-state
<RX14> and blame until i find the refactoring
<RX14> then i can press enter to get to the commit
<RX14> search for accept( in that diff
<Yxhuvud> well still easier than using github for it
<RX14> then press enter on the deleted line to open the buffer to the file as-is before that commit
<RX14> then blame on THAT buffer
<RX14> which si way easier than github
A124 has quit [Ping timeout: 240 seconds]
<FromGitter> <konovod> ⏎ ⏎ ```require "random/system" ⏎ u = 0_u64 ⏎ u = Random::System.next_u ⏎ pp u, typeof(u)``` ⏎ ⏎ shows `UInt8`. I think `next_u` is pretty strange method. Why not make next_u32, next_u64? []
<oprypin> konovod, basically you're not supposed to use next_u
<crystal-gh> [crystal] RX14 opened pull request #4788: Fix LibC.accept segfault (master...bugfix/accept)
<oprypin> > It is possible to make a custom RNG by including Random and implementing #next_u to return an unsigned number of a pre-determined type (usually UInt32). The numbers generated by your RNG must be uniformly distributed in the whole range of possible values for that type (e.g. 0u32..UInt32::MAX).
<oprypin> it returns the type that is "native" to this particular RNG
<FromGitter> <konovod> So how to get say random UInt64?
<FromGitter> <konovod> oh, yes, then it's fine.
<oprypin> `rand(UInt64::MIN..UInt64::MAX)`
<RX14> oprypin, perhaps the kernel will write more than sizeof(struct sockaddr) when it can, for performance reasons around unaligned memory?
<oprypin> that's too far down the rabbit hole
<RX14> lol
<oprypin> maybe the problem is size mismatch and the actual sckaddr it tries to write is bigger
<oprypin> u said there can be different ones
<RX14> perhaps
<RX14> yes but looking again
<RX14> they're all the same size?
<oprypin> konovod, also just so you're aware, you wrote `u = 0_u64` but it can have absolutely no effect on consequent assignments to it
<oprypin> assignment to a variable always makes the type of the variable the same as what was assigned to it, regardless of previous uses of that variable name
<oprypin> i seem to notice this misconception often lately, maybe some docs need to clarify this
<RX14> variables don't exist, we just have SSA but they're all named the same and every usage is a phi node
<FromGitter> <konovod> @oprypin yeah, i was totally wrong. It would have effect in a field, but local var is just overwritten.
<oprypin> it would have an effect of a compile error due to type mismatch but yeah
zaiste has joined #crystal-lang
A124 has joined #crystal-lang
<crystal-gh> [crystal] konovod opened pull request #4789: Seed PRNGs from System source instead of time (master...rng_seed)
<crystal-gh> [crystal] RX14 opened pull request #4790: Fix WeakRef specs in release mode (master...bugfix/weakref-specs)
imnotjustarobot has joined #crystal-lang
<imnotjustarobot> hello!
<RX14> hi
<imnotjustarobot> where can I get an interactive crystal? like IRB, the interactive ruby
<RX14> crystal play
<RX14> you can write code in there and get output in your browser
<imnotjustarobot> but this is not the interactive crystal i expected
<imnotjustarobot> is there not an interactive crystal like irb?
<RX14> what do you need an interactive crystal for?
<imnotjustarobot> like irb
<RX14> if it's trying out snippets of code, you should use crystal play
<RX14> if it's trying to use it as a debugger
<RX14> well, you can't
<RX14> it's impossible because crystal is compiled and statically typed
bcardiff has quit [Quit: bcardiff]
<imnotjustarobot> but i can remember that there was somewhere in the universe an interactive crystal like irb..
<RX14> there is but it doesn't work like irb in any way
<imnotjustarobot> how can I half a number? is there an method for this?
<RX14> divide it by two?
<imnotjustarobot> oh
<crystal-gh> [crystal] matiasgarciaisaia pushed 1 new commit to master:
<crystal-gh> crystal/master e85746f RX14: Fix LibC.accept segfault
<imnotjustarobot> but what if i want to half a 1
<RX14> so you want a float? just use to_f on one of the operands
<RX14> like if you want to do variable / 2 use variable.to_f / 2
<RX14> or just store variable as a float in the first place if you want non-integer values
snsei has joined #crystal-lang
A124 has quit [Quit: '']
<crystal-gh> [crystal] matiasgarciaisaia opened pull request #4791: Merge 0.23.1 into master (master...release/0.23)
A124 has joined #crystal-lang
<travis-ci> crystal-lang/crystal#e85746f (master - Fix LibC.accept segfault): The build passed.
<travis-ci> crystal-lang/crystal#e85746f (master - Fix LibC.accept segfault): The build passed.
imnotjustarobot has quit [Quit: Page closed]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 258 seconds]
bcardiff has joined #crystal-lang
<crystal-gh> [crystal] RX14 pushed 1 new commit to master:
<crystal-gh> crystal/master 0906a88 Chris Hobbs: Fix WeakRef specs in release mode (#4790)
renich has quit [Quit: Renich]
renich has joined #crystal-lang
<FromGitter> <code-andres> imnotjustarobot here ICR ->
bcardiff has quit [Quit: bcardiff]
bcardiff has joined #crystal-lang
<travis-ci> crystal-lang/crystal#0906a88 (master - Fix WeakRef specs in release mode (#4790)): The build passed.
bcardiff has quit [Client Quit]
snsei has joined #crystal-lang
<travis-ci> crystal-lang/crystal#0906a88 (master - Fix WeakRef specs in release mode (#4790)): The build passed.
snsei has quit [Remote host closed the connection]
sauer2 has joined #crystal-lang
<sauer2> Hi."%s") returns the time from the UNIX date in seconds. I didn't find a format option to return it in milliseconds. Is there such an option?
<sauer2> Or was it left out due to precision shenanigans?
<RX14> sauer2, you want #epoch_ms
<RX14> sauer2, because to_s is decimal you can concat %s%L and get the same result, but please just use #epoch_ms.to_s
<sauer2> @RX14: That works, thank you!
<sauer2> Oh, another question that came up: Does Crystal have anonymous classes?
<RX14> no
<RX14> what's the usecase?
<sauer2> injecting function containers into an interpreter
<sauer2> maybe for command patterns in general
<RX14> well in crystal, classes and modules and that aren't *really* values
<RX14> they are in ruby
<RX14> but in crystal it's all just smoke and mirrors
<RX14> so a lot of things would break with anonymous classes, they already do with private classes
<RX14> would file-private classes help?
<sauer2> No idea, but it is mostly a convenience issue at worst, since I have to write the function containers down and then pass an instance to the interpreter instead of passing an anonymous class.
<sauer2> There might be even a better solution, since the code in question was ported from Java.
<RX14> well i'd recommend just naming the classes
<sauer2> @RX14: those can be passed directly?
<RX14> no
<sauer2> Hm. If it weren't a textbook text but a real world scenario, metaprogramming might have worked...
<sauer2> Oh well, anyway, thanks for your time.
<RX14> i don't think this is a valid usecase for metaprogramming of the top of my head
<RX14> but i don't know the details so...
<sauer2> @RX14 Why not? The functions might be considered part of the interpreter itself instead of injecting them at runtime. But that kind of stuff may only be possible with full compile time AST manipulation as shown in JAI; not sure if it's possible with replacement macros.
<RX14> what do you mean injecting them at runtime
<sauer2> I mean, if the interpreter is embedded in a host application you might want to provide application specific functions, for automation, macros, etc.
rohitpaulk has quit [Ping timeout: 240 seconds]
<sauer2> So when you create the interpreter instance you first have to register application specific functions at it.
rohitpaulk has joined #crystal-lang
<sauer2> @RX14 It's basically what people do with Lua.
sauer2 has quit [Quit: Page closed]
alibby has quit [Quit: Leaving.]
zaiste has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Qwerp-Derp> I have an issue with my Crystal code:
<shelvacu> What's the problem?
<shelvacu> Do you need all of that code to reproduce the problem?