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
repo1 is now known as repo
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 245 seconds]
f1reflyylmao is now known as f1refly
<FromGitter> <mattrberry> @oprypin:matrix.org Offset by one int? I just tested and I have to offset the SDL::Event pointer by 2 ints in order to get the expected value Could this be some difference between systems? Is there documentation on how crystal lays out its memory?
<FromGitter> <mattrberry> This works for me currently without your fix to sdl.cr ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60bd7a2f5bf7ed10d3e71b19]
Vexatos has quit [Read error: Connection reset by peer]
Vexatos_ has joined #crystal-lang
markmarkmark has quit [Ping timeout: 272 seconds]
markmarkmark has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
Guest97 has joined #crystal-lang
Guest97 has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> is there a naming convention related to when a setter has more than 1 arg? E.g. `def default_command(name : String, single_command : Bool = false)` versus `def set_default_command(name : String, single_command : Bool = false)`
<FromGitter> <naqvis> AFAIK crystal doesn't make use of `get_`, `set_`
<FromGitter> <naqvis> i mean conventionally
Guest97 has joined #crystal-lang
Guest97 has quit [Client Quit]
Guest49 has joined #crystal-lang
<FromGitter> <Dan-Do> at runtime, is there any way to show stats of running fiber?
<FromGitter> <Dan-Do> I want to know which fiber is blocking the main thread
<FromGitter> <Dan-Do> 👍
Guest49 has quit [Ping timeout: 250 seconds]
<FromGitter> <Dan-Do> @naqvis The thing is I don't know which method/shard create the fiber :(
<FromGitter> <Dan-Do> In the example, this code is the owner of fiber ⏎ ⏎ ```f = spawn(name: "worker") do ⏎ foo(ch) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=60bdb31c1e6aa460c0157b87]
<FromGitter> <naqvis> not sure I follow
<FromGitter> <naqvis> your code is not the one creating the fibers?
<FromGitter> <Dan-Do> no, I don't create any fiber. I am using many shards like kemal, db, html5 (yours :))... so I am not sure
<FromGitter> <naqvis> I haven't tested this, but guess you can have that extension code (in above forum link) and then somewhere in your code you can try to invoke ⏎ `Fiber.current.print_backtrace` and see if it works for you
sorcus has quit [Ping timeout: 244 seconds]
sorcus has joined #crystal-lang
<FromGitter> <Dan-Do> It returns `running, unable to get backtrace`
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <naqvis> how about ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60bdbdaf19b46c60b1727168]
<FromGitter> <naqvis> this way you can invoke `print_backtrace` on all fibers
<FromGitter> <Dan-Do> `Error: can't infer the type of class variable '@@first_fiber' of Fiber`
<FromGitter> <naqvis> aahh, API has changed
<FromGitter> <naqvis> so you needn't to add that `self.list` related code
<FromGitter> <naqvis> just use `unsafe_each`
<FromGitter> <naqvis> so in summary, just use the extension code in forum post and then run ⏎ `Fiber.unsafe_each {|f| pp f, f.print_backtrace}` do get backtrace of all fibers
<FromGitter> <Dan-Do> yeah, just found that :)
<FromGitter> <naqvis> 👍
dom96 has quit [Ping timeout: 272 seconds]
dom96 has joined #crystal-lang
arestifo has joined #crystal-lang
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 264 seconds]
<FromGitter> <mattrberry> Hey @oprypin I know you've worked with this before so maybe you know a bit more. Since cimgui builds a shared object file, is there any way for me to link that without setting the LD_LIBRARY_PATH? Ideally any project that wanted to use crystal-imgui-backends could just put it in the shard.yml and not have to think about it any further. I already have the postinstall script building everything, but then I
<FromGitter> ... currently still need to set LD_LIBRARY_PATH so that it can link at runtime
deavmi has quit [Ping timeout: 272 seconds]
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
deavmi has joined #crystal-lang
hightower3 has joined #crystal-lang
arestifo has joined #crystal-lang
hightower3 has quit [Ping timeout: 252 seconds]
Guest49 has joined #crystal-lang
<FromGitter> <Blacksmoke16> @naqvis I guess my thinking is should it use `set_` in this context to make it more clear it's a setter versus a getter with args? Or does have the option required argument make that clear enough
<FromGitter> <naqvis> yeah agree having clear and concise name removes the ambiguity and make the intention clear. But I was talking about crystal conventions of not using such naming style to highlight the purpose of the method. Just did a quick search in api for methods starting with `set_` and there are very few 14 or so, and majority of them are part of FFI related stuff
<FromGitter> <naqvis> but, if method name make things more clear, I will definitely go with using the name which make things more obvious to its users
Guest49 has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> heres an example, which do you like better?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be1c9881b45810b88cee6c]
<FromGitter> <naqvis> first one is obvious enough, so I'll go with that
<FromGitter> <naqvis> because method in that context is making things clear that its setting XXXX
<FromGitter> <Blacksmoke16> 👍 cool, because that's what i went with
<FromGitter> <Blacksmoke16> imma just go with it, always can deprecate them in favor of something else later on. But this is fine for initial implementation
Guest49 has joined #crystal-lang
<FromGitter> <naqvis> 👍
Guest49 has quit [Client Quit]
jhass[m] has quit [Quit: node-irc says goodbye]
jcs has joined #crystal-lang
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
arestifo has joined #crystal-lang
<FromGitter> <Dan-Do> in mt mode, why `@ivar` of difference instances is shared and overwritten by fibers?
<FromGitter> <erdnaxeli:cervoi.se> it should probably not. Do you have some code to show this behavior?
<FromGitter> <Dan-Do> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be2ff81477ff6954a69fca]
<FromGitter> <Dan-Do> without MT, the result is correct. When built with MT, it's wrong
<FromGitter> <naqvis> might be you writing to console is getting switched between fibers, thus giving you feelings of its being overwritten
<FromGitter> <Dan-Do> just an example, real code return the `@result, @code` to http response to browser
<FromGitter> <naqvis> suppose you have two fibers F1, F2, F1 writing to console some output and then get scheduled out due to IO , F2 get its turn and start writing to console
<FromGitter> <erdnaxeli:cervoi.se> yes, you should trying to return the result instead
<FromGitter> <Dan-Do> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be31c3ae78084ee729fb4f]
<FromGitter> <wyhaines> @ddd It's the same answer to this question as to all of them that you have asked for the last several days. ⏎ ⏎ If you are using threads, you either *can not* share state, or you *must* synchronize the use of shared state. ⏎ ⏎ Either use channels to communicate between your threads, and don't share anything, or use a Mutex to syncrhonize the access to shared state. ...
<FromGitter> <erdnaxeli:cervoi.se> but here he is not sharing state (with the real code example)
<FromGitter> <Dan-Do> yeah, in my above example, I don't share anything. the `query` is created in every request of `get "/person"`
<FromGitter> <Dan-Do> if I print the hash of query, it's different every times ⏎ ⏎ ```query = DB.new ⏎ p query.hash``` [https://gitter.im/crystal-lang/crystal?at=60be329781b45810b88d24a1]
<FromGitter> <Dan-Do> I debug this issue several days but don't know how to solve
<FromGitter> <Blacksmoke16> whats the problem exactly? you're seeing things get printed to your console out of order? Is the actual response body correct?
<FromGitter> <Dan-Do> No, I return json to broswer `{"result": r.result, "count": r.count}.to_json`
<FromGitter> <wyhaines> "in mt mode, why `@ivar` of difference instances is shared and overwritten by fibers?" ⏎ ⏎ If that is actually happening, then there is shared state. In the example from last week where it superficially looked like variables were getting changed in a strange when when running MT, what was really happening was just that the diagnostic output to the screen was getting mixed by parallel threads. ⏎ ⏎
<FromGitter> ... Without complete context, I can't say where the shared state exists this time, but if one fiber is overwriting the value of an instance variable in unexpected ways, that is because the access to that instance variable is shared, and unsynchronized. [https://gitter.im/crystal-lang/crystal?at=60be33640f247f448ea231e8]
<FromGitter> <Blacksmoke16> > No, I return json to broswer `{"result": r.result, "count": r.count}.to_json` ⏎ ⏎ So what's the problem?
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <erdnaxeli:cervoi.se> do you have a fully working example showing the bug?
<FromGitter> <erdnaxeli:cervoi.se> I tried this but it works as expected: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be339a5e3ef60161eb20e4]
<FromGitter> <Dan-Do> @wyhaines @erdnaxeli:cervoi.se Thanks, I will look at the code more carefully to find the shared vars
<FromGitter> <wyhaines> @erdnaxeli:cervoi.se Add a short sleep into your *#execute*, to simulate waiting on some IO. `sleep(rand)` is sufficient. And then hit the kemal server with a number of concurrent requests. I would bet that there are parts of Kemal that are not threadsafe.
<FromGitter> <wyhaines> I mean, there are common parts of the stdlib that are not threadsafe, so it's almost certain that kemal has some threadsafety issues, too.
<FromGitter> <erdnaxeli:cervoi.se> hmm I still don't see responses with invalid values, but my test is only `while true; do curl localhost:3000/person & done`
<FromGitter> <wyhaines> Yeah. So that is itself sequential.
<FromGitter> <Dan-Do> @erdnaxeli:cervoi.se Can you try wrk to open multiple threads?
<FromGitter> <Dan-Do> but I don't think your code would raise that issue :)
<FromGitter> <erdnaxeli:cervoi.se> it is concurrent, I ran 2k curl during some seconds
<FromGitter> <erdnaxeli:cervoi.se> so you need to find some code that raises the issue
<FromGitter> <Dan-Do> like @wyhaines said, there must by shared vars somewhere
<FromGitter> <erdnaxeli:cervoi.se> yeah I'm sure too :)
jhass[m] has joined #crystal-lang
arestifo has joined #crystal-lang
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
arestifo has joined #crystal-lang
<FromGitter> <Dan-Do> Does the different IO (of TCPSocket) have different file descriptor?
<FromGitter> <wyhaines> This is the hard thing about multithreaded programming. One doesn't have to look very far to find examples of shared state. Even in ubiquitous code like the Hash implementation, if you have two threads which are assigning to the same hash at the same time, they can stomp on each other in bad ways. ⏎ ⏎ And I'm sure that the HTTP Server implementation in the stdlib isn't thread safe, so there is definitely
<FromGitter> ... the potential for fun there. ⏎ ⏎ It would be an interesting exercise to try to make it threadsafe. [https://gitter.im/crystal-lang/crystal?at=60be43c55f235f695078866b]
<FromGitter> <Dan-Do> I am looking forward to seeing that
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <rishavs> What is a simple way to get the request params coded in the requets body (eg for POST requests)? ⏎ Currently I am using a model class with a JSON:Serializable attribute but its overkill for my usecase ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be533f1477ff6954a6ffc8]
<FromGitter> <Blacksmoke16> i.e. you want to switch from json data to form data?
<FromGitter> <rishavs> No. I still want to use request body for the payload. But was wondering if I have to use a JSON serializable approach to get this payload
<FromGitter> <Blacksmoke16> as opposed to what?
<FromGitter> <Blacksmoke16> `JSON.parse`?
<FromGitter> <Blacksmoke16> you already have the request body contents, `body.try &.gets_to_end`
<FromGitter> <rishavs> i know. Was thinking we may have a convenience method around this 😅
<FromGitter> <Blacksmoke16> nope
<FromGitter> <Blacksmoke16> could do something like this tho
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be54951e6aa460c016f8a4]
<FromGitter> <Blacksmoke16> imo doing what you're doing is a good approach. could also look into using the `record` macro tho
<FromGitter> <Blacksmoke16> ```record Req, user_email : String, password : String do ⏎ include JSON::Serializable ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=60be54cb84c2f15b7968225a]
<FromGitter> <rishavs> Thanks! I was thinking of getting rid of the classes as I don use the typical "models" in my code. But I guess it is indeed the proper way of doing things. 👍
<FromGitter> <Blacksmoke16> er, backing up. What are you doing with the `req` object here/
<FromGitter> <Blacksmoke16> like just using it as a means to access the data, or also doing like `req.password = ...`?
<FromGitter> <rishavs> just to access the data. after that i never touch that class
<FromGitter> <Blacksmoke16> ok, then yea, using a record will be perfect
<FromGitter> <Blacksmoke16> how are you handling validation of the data?
<FromGitter> <Blacksmoke16> https://en.wikipedia.org/wiki/Data_transfer_object is technically what this pattern is. keeps your domain entities separate from the input/output data
<FromGitter> <rishavs> Ghetto style 😅 ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be565319b46c60b173daf5]
<FromGitter> <Blacksmoke16> ahh right. I think we talked about this before :P
<FromGitter> <Blacksmoke16> `Form data validation failed` technically the data isn't form data fwiw
<FromGitter> <rishavs> I know. "Use a framework instead of screwing around" 😅
<FromGitter> <rishavs> > `Form data validation failed` technically the data isn't form data fwiw
<FromGitter> <rishavs> yeah, WIP. on the messages. I just put in something for myself to track
<FromGitter> <Blacksmoke16> 👍 fair enough
<FromGitter> <Blacksmoke16> good call on using exceptions for that. I find it works quite well
<FromGitter> <rishavs> Thanks! ❤️
<FromGitter> <Blacksmoke16> is how i handle it Athena as well 😉
jhass[m] has quit [Ping timeout: 272 seconds]
<FromGitter> <Dan-Do> Though I am not 100% sure, the problem solved by changing the local var name of each request path
<FromGitter> <Dan-Do> Former code I use the same var name
<FromGitter> <Blacksmoke16> 🤔
<FromGitter> <Dan-Do> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be663c5bf7ed10d3e940f2]
<FromGitter> <Dan-Do> After changing the `query` in `/bar` to `q_test`, the issue gone for 3 tests
<FromGitter> <Dan-Do> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60be669f5e3ef60161eba964]
foxxx0 has joined #crystal-lang
<FromGitter> <Blacksmoke16> :shrug:
jhass[m] has joined #crystal-lang
postmodern has joined #crystal-lang
<yxhuvud> @straight-shoota: regarding that ci error, have you verified that things like stacktraces from spawned fibers are printing like they should? Lots of what you are doing is happening in between fibers after all.
<straight-shoota> at this point there is no fiber switching involved
<straight-shoota> it happens all in the main fiber: issue an operation, wait for it to finish, collect the completed result
<yxhuvud> Have you tried putting a rescue where it seems to fail and print what you get?
<yxhuvud> that of course requires finding the place which may be nontrivial.
<straight-shoota> exactly that is the problem
<straight-shoota> =)
<straight-shoota> I'll probably have to put in a series of puts beacons
<yxhuvud> yes, except it is not obvious you can trust puts to work. Crystal::System.print_error is the way to go :)
<straight-shoota> probably better, yes
<yxhuvud> I've literally had unrelated tests fail *because* I used puts in some places.
<straight-shoota> o_o
<yxhuvud> it turned out io_uring didn't support writing to STDOUT in versions < 5.8. oops.
<yxhuvud> so I only got EAGAIN.
Guest7 has joined #crystal-lang
Guest7 has quit [Client Quit]
<yxhuvud> and I had only a test on write, not on writing to stdout in particular.
riza has joined #crystal-lang
sorcus has quit [Quit: WeeChat 3.1]
<riza> hey hey crystal made it on the list of Stack Overflow questions
sorcus has joined #crystal-lang
Guest13 has joined #crystal-lang
Guest13 has quit [Client Quit]
<FromGitter> <Daniel-Worrall> Wan't it already?
Guest17 has joined #crystal-lang
<riza> it wasn't last year, I had to write it in
<FromGitter> <oprypin:matrix.org> i think this is talking about their yearly usage survey
Guest17 has quit [Quit: Client closed]
<riza> that's right, sorry.
Guest936 has joined #crystal-lang
<Guest936> Wow star studded chat, its got some big contributors, thank you for crystal it's super sweet, bye y'all!
Guest936 has quit [Client Quit]
<FromGitter> <Blacksmoke16> 🤔
Juanse has joined #crystal-lang
Juanse has quit [Client Quit]
<riza> hah