Skip to content

Safelocks

David Vorick requested to merge safelocks into master

This PR depends on the other one I have open. (#388)

I created a lock package, it records who locked it and it complains if there's a deadlock, and it also automatically fixes the deadlock. It also prints a call stack, so you can see who caused the deadlock.

The current implementation results in thousands of sleeping goroutines during standard Sia use. I think that we can implement a garbage collection style thread, so that instead of thousands of sleeping goroutines, you just have 1 that runs every 2 seconds or so and checks the timestamps on the lock calls to see if any of them have held a lock for too long. Then you'll only have 1 thread per unique lock, which should really only be one thread per module. This is much more manageable.

As best I can tell, using the lock package is impacting performance a noticeable amount, but not a significant amount. For now, I have no real desire to implement the garbage collection style manager. Probably best to leave it.

This PR also fixes a few deadlocks, which were discovered thanks to the new mutex type. Debugging was substantially easier once you knew which call wasn't releasing in time. As best I can tell, there's still probably a deadlock somewhere in the transaction pool but I haven't been able to trigger it through testing.

I think that, until performance becomes absolutely necessary, we should leave all production binaries with the protected locking. In the event that a deadlock is triggered, it'll automatically fix itself instead of locking up the program and affecting user experience. I think that we should probably just keep it indefinitely, but then also provide 'performance' binaries that have a lot of the safeties removed.

Right now I call fmt.Printf to talk about any deadlocks that occur. It should probably instead go into a logging file somewhere. I'm not sure the best way to handle that. Also not worried about it for the time being. I'm more concerned about getting the final UX stuff ready. (files/directories, indications of failed uploads/downloads, auto-repair, and some indication for the host of how much money total has been made from offering storage).

Merge request reports