ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
ejjfunky has joined #crystal-lang
ur5us has joined #crystal-lang
waleee has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 240 seconds]
SamantazFox has quit [Remote host closed the connection]
SamantazFox has joined #crystal-lang
ur5us has joined #crystal-lang
ejjfunky0 has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
wolfshappen has quit [Ping timeout: 240 seconds]
wolfshappen has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
brw has quit [Read error: Connection reset by peer]
brw has joined #crystal-lang
taupiqueur has joined #crystal-lang
brw has quit [Read error: Connection reset by peer]
brw has joined #crystal-lang
brw has quit [Read error: Connection reset by peer]
brw has joined #crystal-lang
notzmv has quit [Ping timeout: 252 seconds]
brw has quit [Read error: Connection reset by peer]
brw has joined #crystal-lang
ejjfunky0 has quit [Remote host closed the connection]
brw has quit [Read error: Connection reset by peer]
brw has joined #crystal-lang
brw has quit [Read error: Connection reset by peer]
brw has joined #crystal-lang
<FromGitter> <oprypin:matrix.org> moe (https://matrix.to/#/@moe:busyloop.net): https://github.com/anykeyh/crystal-coverage ?
<FromGitter> <oprypin:matrix.org> it is indeed *relatively* straightforward but not trivial. and then also difficult how to present the results.. unless there are widely used standards that make it obvious..?
taupiqueur has quit [Quit: taupiqueur]
taupiqueur has joined #crystal-lang
taupiqueur has quit [Client Quit]
taupiqueur has joined #crystal-lang
<FromGitter> <moe:busyloop.net> oprypin (https://matrix.to/#/@oprypin:matrix.org): hmm true. i guess doing it right will take a bit more work than my naive approach. after some looking it seems like `gcov` is the big daddy in the space. they seem to support a JSON format (search for "json" in https://man7.org/linux/man-pages/man1/gcov.1.html) which is supported by a variety of report generators / CI tools (e.g. jenkins or lcov;
<FromGitter> <moe:busyloop.net> well, probably not the highest prio in the grand scheme of things. ⏎ i wonder if the instrumentation could perhaps also help with error messages tho. (line numbers tend to be all over the place in recent crystal versions for me when macros get involved)
<FromGitter> <moe:busyloop.net> fwiw, it looks like there are various degrees of "doing it right". e.g. go-lang apparently only does line-coverage https://gitlab.com/stone.code/scov#using-go - so that may be good enough for a future first version in crystal as well
ejjfunky0 has joined #crystal-lang
notzmv has joined #crystal-lang
notzmv has quit [Ping timeout: 256 seconds]
taupiqueur has quit [Ping timeout: 256 seconds]
taupiqueur has joined #crystal-lang
taupiqueur has quit [Ping timeout: 256 seconds]
taupiqueur has joined #crystal-lang
<FromGitter> <y8> @naqvis I'm writing wasm interpreter in crystal. It's stack based ISA for abstract "hardware". There is tons of instructions with different shapes: bytesize, how many values it pops/pushes on stack, immediate values arity, memory/locals/globas access & etc. Almost all instructions interact with stack, so I decided to specialize them using generic module "inheritance" based on "stack arity". ⏎ ⏎ What I don't
<FromGitter> ... like in current approach, is that vm instance is passed to context where instructions are computed, even if they don't require VM. But I can live with it
<FromGitter> <y8> Is there a way to add element to array and get its new index?
<FromGitter> <y8> At the same time I mean, without getting size and all
<FromGitter> <naqvis> `Array#size` is just a simple wrapper against internal variable `@size`, so calling `size` on array is not going to traverse the whole to return the count. `Array#push` returns the same array object, so you can get the index via ⏎ ⏎ ```arr = [1,2,3] ⏎ index = arr.push(4).size - 1 # => 3``` [https://gitter.im/crystal-lang/crystal?at=62125749f43b6d783fc6b314]
<FromGitter> <moe:busyloop.net> https://carc.in/#/r/cstq
<FromGitter> <moe:busyloop.net> why does String not have a ctor that takes a String? 🤔
<FromGitter> <Blacksmoke16> fwiw, the numeric constructors essentially just call like `.to_i32` on whatever you pass it
<FromGitter> <Blacksmoke16> for string that would be `.to_s`
<FromGitter> <moe:busyloop.net> yup. it's not a big deal, just surprised i had to make a special case for String in my little env-var macro
<FromGitter> <Blacksmoke16> could always just monkey patch in a constructor to do it
<FromGitter> <moe:busyloop.net> yeh that's what i did first, but then took it out again. probably not gonna release this one as a shard anyway, but not a fan of patching base-classes in general.
<FromGitter> <Blacksmoke16> if you do, might not be a bad idea to name it something else, like `.from_env_value` or something
<FromGitter> <moe:busyloop.net> yeh at the moment i just do `{{type}}.new(str_val)`
<FromGitter> <moe:busyloop.net> yeh it's fine i'm good, just caught me by surprise
<FromGitter> <Blacksmoke16> 👍
notzmv has joined #crystal-lang
<FromGitter> <naqvis> > why does String not have a ctor that takes a String? 🤔 ⏎ ⏎ String is immutable, so technically speaking calling ctor with String is just going to return a copy of the same. So it really doesn't make any difference to either assign string obj to new obj or call it via ctor.
<FromGitter> <moe:busyloop.net> yup, probably a bit of a special case here. was just surprised it doesn't just return a cpoy
<FromGitter> <moe:busyloop.net> https://carc.in/#/r/csu6 - in hindsight guess it would be nicer to sneak in a "Converter"-class anyway, or monkeypatch `#from_env` like blacksmoke said rather than relying on `#new`. but anyweh, good enough for me for now.
ejjfunky0 has quit [Remote host closed the connection]
ejjfunky has quit [Ping timeout: 256 seconds]
<SamantazFox> Blacksmoke16: Ok, so I tried to compile crystal while using got bisect, and uhhhh... It doesn't work, but in a different manner than what I was having on crystal 1.3.0
<FromGitter> <Blacksmoke16> oh?
<SamantazFox> I'm getting 502 bad gateway from ngninx
<SamantazFox> nginx*
<FromGitter> <Blacksmoke16> is the server actually running?
<SamantazFox> yeah, because the favicon shows up.
<SamantazFox> it's the only thing that works)
<FromGitter> <Blacksmoke16> would it be possible to extract the part with the error to a single file that returns exit code 1 or 0?
<FromGitter> <Blacksmoke16> versus long running server
<SamantazFox> nope, because there are many layers between the client (the browser) and said code
<FromGitter> <Blacksmoke16> rip
<SamantazFox> There is Kemal, the `before_all` logic, the routing, etc...
<FromGitter> <Blacksmoke16> guess you could always just do it the hard way. I.e. do what bisect does but manually
<SamantazFox> yep, but that probably won't work either
<SamantazFox> I'm thinking that my home-made compiler is definitely missing something.
<FromGitter> <Blacksmoke16> i.e. assert you have the issue on 1.3.x and not on 1.2.x then pick the commit halfway between, see if you still have an issue, then go halfway between 1.2.x and the last commit
<SamantazFox> that's what I'm doing!
<FromGitter> <Blacksmoke16> oh well, step 1 would be to ensure you can actually use locally compiled version to run it
<FromGitter> <Blacksmoke16> are you doing like `make clean && make all && ./bin/crystal app.cr`?
<FromGitter> <Blacksmoke16> because thats all there should be to it
<SamantazFox> `cd crystal.git; make clean && make clean_cache && make crystal release=1 progress=true; cd ../invidious.git; make RELEASE=0 DISABLE_QUIC=1 && make deploy`
<SamantazFox> (I've edited my Makefile to point to `<HOME>/crystal.git/bin/crystal` instead of just `crystal`)
<FromGitter> <Blacksmoke16> oh jezz, well i dont think you need to compile crystal in release mode, that would take like 10-20min
<FromGitter> <Blacksmoke16> `cd crystal.git; make clean && make all; cd ../invidious.git; make RELEASE=0 DISABLE_QUIC=1 && make deploy` id just try this
<SamantazFox> I already did!
<FromGitter> <Blacksmoke16> and there's not compiler/runtime errors?
<FromGitter> <Blacksmoke16> no*
<SamantazFox> nope
<SamantazFox> nothing at all
<SamantazFox> Here's the log for one step: https://bpa.st/62PQ
<SamantazFox> (`$HOME` is `/srv/invidious/`, if you wonder)
<FromGitter> <Blacksmoke16> what happens if you try a simpler program with it
<FromGitter> <Blacksmoke16> like `puts "foo"`
<FromGitter> <Blacksmoke16> just to assert the local compiler is working
<SamantazFox> I'm pretty sure that it will work.
<SamantazFox> As I said, it manages to return the favicon
<SamantazFox> (so via the `public_folder "assets"` system of Kemal)
waleee has joined #crystal-lang
<FromGitter> <Blacksmoke16> is there an easy way to validate the issue locally?
<SamantazFox> `curl localhost:3000/latest_version?id=9t6jImyvnQk&itag=22&local=true`
<FromGitter> <Blacksmoke16> apparently im missing a `config/config.yml` file?
<FromGitter> <Blacksmoke16> oh nvm, theres a sample one
<SamantazFox> Oh, yeah...
<SamantazFox> I'd recommend to remove all routes but the video playback ones (they're defined in the main source file)
<SamantazFox> Otherwise, you'll need a Postgres DB
<FromGitter> <Blacksmoke16> thats fine, compose file is easy enough :0
<FromGitter> <Blacksmoke16> ;)
<SamantazFox> ha, nice ^^
<FromGitter> <Blacksmoke16> alright, so whats the issue exactly? i went to that url and am watching a video
<SamantazFox> with what version of crystal?
<FromGitter> <Blacksmoke16> 1) 3.2
<SamantazFox> ok, check your devtools
<SamantazFox> there are multiple queries failing
<SamantazFox> Note that it doesn't always prevent playback (E.g I can watch videos fine on Firefox and Chrome-based browsers, but that makes Safari go "nope")
<FromGitter> <Blacksmoke16> you mean http requests?
<SamantazFox> yep
<FromGitter> <Blacksmoke16> seems fine?
<SamantazFox> wtf O.o
<FromGitter> <Blacksmoke16> :shrug:
<SamantazFox> That's somewhat part of my problem... depending on the browser and the host system, I get inconsistent results
<SamantazFox> Oh, wait, The link I gave you is "normal" video.
<SamantazFox> try this one ^
<SamantazFox> if you look at the console, the VideoJS player gets confused
<SamantazFox> (I've made a fix on my own instance to solve that DASH playback problem, which breaks the non-DASH playback instead).
<FromGitter> <Blacksmoke16> okay yea, that one fails and are a lot more requests
<SamantazFox> Yeah!
<SamantazFox> And so, what I've done is to remove the ugly loop in `srv/invidious/routes/video_playback.cr` and instead just copy the data returned by Google servers.
<FromGitter> <Blacksmoke16> okay so using 1.2.2, i still get a lot of requests, but none of them fail
<SamantazFox> yeah, that's normal. DASH works by very small data chunks
<SamantazFox> Where as "normal" video (non-DASH) is streamed like a normal large file.
<SamantazFox> When I remove the loop (https://github.com/iv-org/invidious/pull/2900/files, but comment out the `2.times`) this has the effect of closing the connection, and the browser naturally requests the next byte range.
<SamantazFox> And that's where I hit the "double `FIN`" problem.
<FromGitter> <Blacksmoke16> let me play with bisect a bit
<FromGitter> <Blacksmoke16> hmm well first commit it just doesnt work at all 🤔 ⏎ ⏎ > The media could not be loaded, either because the server or network failed or because the format is not supported.
<SamantazFox> yup, seems familiar xD
<SamantazFox> what do your devtools say?
<FromGitter> <Blacksmoke16> failure on `/api/manifest/dash/id/...`
<FromGitter> <Blacksmoke16> > TTP error: status code undefined, net::ERR_EMPTY_RESPONSE
<FromGitter> <Blacksmoke16> HTTP*, also got that in console
<SamantazFox> yup, that's the beginning of my problem!
<SamantazFox> btw, try to go on https://test.invidious.io/
<SamantazFox> You'll see that DASH works as expected, but non-DASH now fails
<SamantazFox> `Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=62127e9f9a09ab24f36ba782]
<FromGitter> <Blacksmoke16> id say thats prob your problem
<FromGitter> <moe:busyloop.net> ha! hmmm.
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=62127f81d1b64840db2f298f]
<FromGitter> <Blacksmoke16> is a trace from loading the video
<FromGitter> <Blacksmoke16> seems the underlying IO of the response is closed
<FromGitter> <moe:busyloop.net> aha. my money would've been on the headers
<FromGitter> <moe:busyloop.net> interesting one 🤔
<SamantazFox> But I'm not getting any error....
<FromGitter> <moe:busyloop.net> it sounds like it's trying to set `content_length=` after the output is already closed
<FromGitter> <Blacksmoke16> SamantazFox: well it deff works for me on the commit before that one so :shrug:
<FromGitter> <Blacksmoke16> on that and after i get that `The media could not be loaded ...` error
<SamantazFox> welp, that's nice if that's my issue ^^
<SamantazFox> https://bpa.st/54AA
<SamantazFox> here's what I have on the server. basically, it's a fix to treat DASH (small packets) and non-DASH (larger packets) differently.
<SamantazFox> yeah, I saw that.
<FromGitter> <moe:busyloop.net> it looks like you (or kemal) are trying to set that header "too late". previously it may have been ignored, but now it checks if the IO is still open
<SamantazFox> on our side, we set the headers before `IO.copy` so that can't be here. So yeah, maybe kemal?
<FromGitter> <Blacksmoke16> reminder headers are sent as soon as you write *any* data to the response
* FromGitter * moe:busyloop.net can already hear that bug shaking in his shoes
<SamantazFox> Blacksmoke16: yeah, I know!
<SamantazFox> And they're exactly what I'd expect
<SamantazFox> So I don't get how that makes the response to be terminated early (like 2kb early)
<SamantazFox> And I can't find where `check_open` is definied, argh!
<FromGitter> <moe:busyloop.net> another wild guess: this is streaming/proxying from another IO, right? possibly a *different* error happens first, and kemal does something weird like trying to render an error-page on top of a response that's already in progress?
<FromGitter> <moe:busyloop.net> (or already closed even)
<SamantazFox> Yeah, we're proxying from the client's response IO. As for the errors, any error would have already terminated the function, and that proxying code shouldn't be reached.
<SamantazFox> any prior error*
<SamantazFox> All of these `client.get` blocks are rescued, and (currently, on my test server) a backtrace should be printed in the event where the `rescue` branch is reached (which doesn't happen apparently, as I have no logs).
<FromGitter> <moe:busyloop.net> hm yea, sounds unlikely then. but may be worth a poke at how much buffering is at play. e.g. something like "response complete and buffered, but an exception bubbles up before it's actually flushed".
<FromGitter> <moe:busyloop.net> do those 0-byte replies have the right headers or are those also busted?
<SamantazFox> I don't have server logs for those, but I think that yes, headers are somewhat valid, as the tested browser (Safari on macOS) is then requesting the right URL (so at least the `Location` header is untouched).
<SamantazFox> you got me thinking: I'm going to try putting a `.flush` call after my `IO.copy`. That could do the trick.
<FromGitter> <Blacksmoke16> > a backtrace should be printed in the event where the rescue branch is reached ⏎ ⏎ Pretty sure this just doesnt magically happen
<FromGitter> <Blacksmoke16> unless you manually log it, or it reaches something that does or prints the backtrace. I.e. some built in exception handler or it goes unhandled
<SamantazFox> yeah, obviously ^^
<SamantazFox> (`LOGGER` is the intance of our log output handler)
<FromGitter> <Blacksmoke16> id try going in an monkey patching `IO#close`
<FromGitter> <Blacksmoke16> er on the response type
<FromGitter> <Blacksmoke16> to print a message when it gets closed and see if it happens more than once
<FromGitter> <Blacksmoke16> AND could also go into `content_type=` to and do like `pp caller` and would give a trace of how that method was called
taupiqueur has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> `#content_length=` rather*
<SamantazFox> `caller` is a macro?
<FromGitter> <Blacksmoke16> Think it's just a method
<SamantazFox> (I'd have monkey patched that with a terrible `begin; raise Foo.new; rescue ex; LOGGER.trace(ex.inspect_with_backtrace); end`
<FromGitter> <Blacksmoke16> Yea, taps into the the exception backtrace logic without raising an exception
<SamantazFox> yeah, much cleaner xD
<SamantazFox> wait, `close` does nothing...
<SamantazFox> nevermind
<SamantazFox> I wasn't looking at the right file...
<FromGitter> <Blacksmoke16> yea, prob want `HTTP::Server::Response#close`
<SamantazFox> yup
taupiqueur has joined #crystal-lang
<SamantazFox> Welp, apparently `HTTP::Server::response.close` is never called....
<FromGitter> <Blacksmoke16> 🤔
<FromGitter> <Blacksmoke16> try `HTTP::Server::Response::Output#close`
<FromGitter> <Blacksmoke16> could be related to https://github.com/kemalcr/kemal/blob/master/src/kemal/ext/response.cr
<SamantazFox> Blacksmoke16: damn it! You know what? That was the culrpit xD
<FromGitter> <Blacksmoke16> oh?
taupiqueur has quit [Ping timeout: 240 seconds]
<SamantazFox> `echo ""> lib/src/kemal/ext/response.cr; make RELEASE=0 DISABLE_QUIC=1 && make deploy`
<SamantazFox> now try to go to https://test.invidious.io :V
<SamantazFox> all videos should work fine
<FromGitter> <Blacksmoke16> nice!
taupiqueur has joined #crystal-lang
taupiqueur has quit [Client Quit]
ur5us has joined #crystal-lang
<SamantazFox> let's hope they'll implement that soon!
<SamantazFox> Blacksmoke16 moe:busyloop.net: And thanks a bunch for your help <3
<FromGitter> <Blacksmoke16> np
ejjfunky has joined #crystal-lang
ejjfunky0 has joined #crystal-lang