Open asuffield opened 3 years ago
I have the beginning of a PR for context cancelation. One blocking point is the behavior on cancel. Should it become an abandon request? This one was not implemented here last time I checked.
Definitely would be a nice feature, I am using context.Context almost everywhere and have some ugly wrapper around the ldap client. Support for it would be great.
SUGGESTION:
How about enhancing the *ldap.Conn
structure with new methods that end with WithContext
to introduce conventional timeout & cancellation semantics to go-ldap.
Example:
// Add performs the given AddRequest
func (l *Conn) Add(addRequest *AddRequest) error
// AddWithContext performs the given AddRequest with a context, the context controls the entire lifetime of a request and its response
func (l *Conn) AddWithContext(ctx context.Context, addRequest *AddRequest) error
// Search performs the given search request
func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error)
// SearchWithContext performs the given search request with a context, the context controls the entire lifetime of a request and its response
func (l *Conn) SearchWithContext(ctx context.Context, searchRequest *SearchRequest) (*SearchResult, error)
...
This would ensure API compatability to the old methods and would not cause breaking changes for an upcoming patch like this. There would be another solution I thought of but it would introduce BREAKING CHANGES, which are most likely not wanted.
cc @Adphi @johnweldon @cpuschma
How about enhancing the
*ldap.Conn
structure with new methods that end withWithContext
to introduce conventional timeout & cancellation semantics to go-ldap.
I like this suggestion in principle. I'm unclear about actual implementation of the timeout and cancellation logic, but there should be ample examples and suggestions in other projects.
I'll knock out an attempt at an initial implementation
I'll knock out an attempt at an initial implementation
I can join if you want :+1:
Here's a first cut: https://github.com/go-ldap/ldap/pull/406
Not mirrored into v3 (yet), just bashing out what the basic API would look like. Probably still buggy.
The same concept has been implemented by other libraries, each method has an equivalent with the option to provide a context.
I would follow the same scheme here
This module currently lacks any support for context.Context, so it can't inherit conventional timeout and cancellation semantics. That seems worth adding.