Skip to content

Take the trace out under the lock and ask for the quota outside it - #1309

Open
Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1224
Open

Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1224

Conversation

@Thayorns

Copy link
Copy Markdown
Contributor

print_trace! held the trace mutex while it asked for the quota. After 100 requests Fbe::Middleware::RateLimit stops serving /rate_limit from its cache and sends a real request, which passes through Fbe::Middleware::Trace, and that one locks the same mutex again on the same thread. So every run with 100 or more requests ended with ThreadError: deadlock; recursive locking, as #1224 shows.

Now print_trace! takes the whole trace out under the lock with slice!, releases the lock, and only then builds the message and calls rate_limit!. The trace is still emptied by the print, and the output is the same as before. Most of the diff is the body losing one level of indentation.

Two tests make over a hundred requests through a WebMock stub and print the trace, once and then twice past two quota refreshes. Both failed with the ThreadError before the change.

Closes #1224

@Thayorns

Copy link
Copy Markdown
Contributor Author

@yegor256 take a look please, happy to clarify anything about this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

print_trace! raises ThreadError: deadlock; recursive locking after 100 requests

1 participant