Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap notifications: add SearchAsync #341

Closed
wants to merge 1 commit into from

Conversation

Adphi
Copy link

@Adphi Adphi commented Sep 9, 2021

Add a SearchAsync function needed to implement ldap notifications (#302).

@Adphi
Copy link
Author

Adphi commented Sep 9, 2021

oops I did not see #319, sorry 😬
should this one be closed ?

@Adphi Adphi force-pushed the search-async branch 2 times, most recently from 92e9bfd to 2c6cba8 Compare September 10, 2021 07:40
@Adphi
Copy link
Author

Adphi commented Oct 15, 2022

@cpuschma, as there is no movement in #319 and here, are there any chances to see this feature implemented?

@cpuschma cpuschma self-assigned this Oct 18, 2022
@cpuschma
Copy link
Member

Sorry for the delay, I'll look into this this week!

@michele-deluca
Copy link

Hi any news on this?

search.go Outdated
@@ -402,6 +439,77 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
}
}

// SearchAsync performs the given search request asynchronously, it returns a SearchAsyncResponse channel which will be
// closed when the request finished and an error, not nil if the request to the server failed
func (l *Conn) SearchAsync(ctx context.Context, searchRequest *SearchRequest) (<-chan *SearchAsyncResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's currently a discussion in another PR regarding context.Context (#406). This would be the only function to accept a context. I suggest to cut out the context handling and wait for the mentioned PR to be merged so we have a streamlined design on how to implement context.Context.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. I'll remove it, but we need a way to stop the receive loop.
Maybe take an optional done channel as parameter to stop when it is closed, e.g.:

// SearchAsync performs the given search request asynchronously, it takes an optional done channel to stop the request. It returns a SearchAsyncResponse channel which will be
// closed when the request finished and an error, not nil if the request to the server failed
func (l *Conn) SearchAsync(searchRequest *SearchRequest, done chan struct{}) (<-chan *SearchAsyncResponse, error)

search.go Outdated
if err != nil {
return nil, err
}
responses := make(chan *SearchAsyncResponse, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike the idea to arbitrary limit or hardcode the channel here to a size of one. This would result in a blocking reader in case the function which called SearchAsync is processing the results or blocking due to other reasons. If we're working with a paging cookie, the LDAP DS could free the cookie to prevent Denial of Service and fetching further results would fail

Any thoughts on this, @go-ldap/committers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your concerns seem reasonable to me @cpuschma; would a blocking call on the client side cause resources on the server side to be tied up indefinitely? What would be the difference to the server (in terms of resource usage, and potential ddos) if it was an unbuffered channel and the reader on the client just stopped reading?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directory servers have a short lease duration for paging cookies, @johnweldon. The overhead for the directory server is therefore very low, unless you intentionally start thousand paging requests without filters. It is more likely that the server will release the cookie. Queries with the PagingControl and the cookie will most likely fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adphi - what is the benefit of a buffered channel here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why, and I don't see any benefit of using a buffered channel here. I'll remove it.

@Adphi Adphi force-pushed the search-async branch 2 times, most recently from 337a51e to bbd6039 Compare January 28, 2023 14:27
Signed-off-by: Adphi <[email protected]>
t2y added a commit to t2y/ldap that referenced this pull request Jun 5, 2023
cpuschma pushed a commit that referenced this pull request Jun 30, 2023
* feat: add search with channels inspired by #319

* refactor: fix to check proper test results #319

* refactor: fix to use unpackAttributes() for Attributes #319

* refactor: returns receive-only channel to prevent closing it from the caller #319

* refactor: pass channelSize to be able to controll buffered channel by the caller #319

* fix: recover an asynchronouse closing timing issue #319

* fix: consume all entries from the channel to prevent blocking by the connection #319

* feat: add initial search async function with channel #341

* feat: provide search async function and drop search with channels #319 #341

* refactor: lock when to call GetLastError since it might be in communication
@t2y
Copy link
Contributor

t2y commented Jul 3, 2023

@cpuschma Can we close this PR by #440 ?

@cpuschma cpuschma closed this Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants