u/ChCkN007_

LLDB is awesome and found a way to foot-gun myself with defer
▲ 34 r/Zig

LLDB is awesome and found a way to foot-gun myself with defer

I've been working on a tcp server and recently started building tests for the server using multiple threads with clients to do partial sends, slow sends, etc and make sure its not blocking the server. I added an atomic flag in the main while loop, instead of while(true), so an outside thread can signal the server to stop running. Then I put a deinit() call after the main loop exits so the server would clean itself up. The problem is that a while ago I put a defer server.deinit() at the top of the test and forgot about it. Today, when I got back to working on the project, I was so confused when my program was aborting with a TRAP signal and no other information.

In school I've picked up a bit of a habit of getting pretty close with my programs/solutions and then turning to llms when I need to debug my code. My excuse has always been that I'm in a hurry to get stuff done, so when I ran into the issue from before, I immediately turned to an llm. It was able to fix a few issues that weren't the root cause but the original error was still there. It always annoys me when I get sucked into a loop of "llm fix this" where nothing gets fixed. In the past I don't usually snapped out of it and turn on my brain, but today I watched this video from JetBrains Academy. It was pretty obvious and yet still the wakeup call I needed. I figured out how to use LLDB with zig and spent 5 minutes stepping through my code and found the error, my server deinit's itself when stopped but I still called defer deinit when I created the server.

Its too easy to outsource your thinking and learning right now.

u/ChCkN007_ — 1 day ago