You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background:
We were using github.com/pb33f/libopenapi-validator in our production code and receiving occasional panics, which I believe match the error shown in #75 (now solved).
These panics were causing a fatal crash in our production code, so we attempted to wrap the method call to ValidateHttpRequest in a recover() in order to ensure it could not result in crashing our application.
After digging into the codebase, we discovered the recover() did not work because ValidateHttpRequest spawns multiple goroutines in order to perform the request validation and thus panics emitted from these goroutines could not be recovered from in our code.
We solved the issue by forking the repo and creating a ValidateHttpRequestSync method that performs the validation synchronously, without any goroutines. This allows the method call to be safely wrapped in recover().
While I believe the particular panic we were seeing has been solved, for use in production we needed to have absolute certainty that a panic or nil-pointer deref emitted in this lib could not lead to a fatal crash of our application.
It's also worth noting that the time savings between ValidateHttpRequest and ValidateHttpRequestSync were negligible in my opinion (16ms vs 21ms, respectively, in my tests). ValidateHttpRequestSync from our fork is currently in use in our production codebase without any issue.
Request:
Add the ValidateHttpRequestSync method to the library so that the user of the library can determine if & how they wish to use goroutines for the request validation, as opposed to goroutines being spawned inside the library, which can lead to unrecoverable panics as shown above.
Background:
We were using
github.com/pb33f/libopenapi-validator
in our production code and receiving occasional panics, which I believe match the error shown in #75 (now solved).These panics were causing a fatal crash in our production code, so we attempted to wrap the method call to
ValidateHttpRequest
in arecover()
in order to ensure it could not result in crashing our application.After digging into the codebase, we discovered the
recover()
did not work becauseValidateHttpRequest
spawns multiple goroutines in order to perform the request validation and thus panics emitted from these goroutines could not be recovered from in our code.We solved the issue by forking the repo and creating a
ValidateHttpRequestSync
method that performs the validation synchronously, without any goroutines. This allows the method call to be safely wrapped inrecover()
.While I believe the particular panic we were seeing has been solved, for use in production we needed to have absolute certainty that a panic or nil-pointer deref emitted in this lib could not lead to a fatal crash of our application.
It's also worth noting that the time savings between
ValidateHttpRequest
andValidateHttpRequestSync
were negligible in my opinion (16ms vs 21ms, respectively, in my tests).ValidateHttpRequestSync
from our fork is currently in use in our production codebase without any issue.Request:
Add the
ValidateHttpRequestSync
method to the library so that the user of the library can determine if & how they wish to use goroutines for the request validation, as opposed to goroutines being spawned inside the library, which can lead to unrecoverable panics as shown above.Example:
Here is the implementation of
ValidateHttpRequestSync
from our fork:https://github.com/pokt-foundation/libopenapi-validator/blob/main/validator.go#L284
The text was updated successfully, but these errors were encountered: