Repository navigation
Conversation
When paging is enabled and the requested size exceeds 126, the client now correctly stops fetching additional pages once the size limit is reached.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Entries can still exceed the documented maximum because the limit is checked only after yielding a complete page.
3 open findings
What changed in this PR
Adds client-side termination for size-limited paged LDAP searches.
Changes:
- Stops paging after reaching the requested size.
- Adds a regression test.
- Updates release history.
| File | Description |
|---|---|
lib/net/ldap/connection.rb |
Adds paging termination logic. |
test/test_ldap_connection.rb |
Tests size-limited paging. |
History.rdoc |
Documents the fix. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Stop paging if we've reached the caller's requested size limit. | ||
| # When paging is enabled, we set query_limit=0 (no server-side limit) | ||
| # for efficiency, so we must enforce the limit client-side here. | ||
| break if size > 0 && n_results >= size |
Comment on lines
+375
to
+392
| # Page 1: 5 entries + result with "more" cookie | ||
| # Page 2: 5 entries + result with empty cookie (shouldn't be reached) | ||
| page1 = 5.times.map { |i| make_search_entry.call("uid=user#{i}") } + [make_search_result.call("more")] | ||
| page2 = 5.times.map { |i| make_search_entry.call("uid=user#{i + 5}") } + [make_search_result.call] | ||
|
|
||
| mock = flexmock("socket") | ||
| write_count = 0 | ||
| mock.should_receive(:write).and_return { write_count += 1 } | ||
| mock.should_receive(:read_ber).and_return(*(page1 + page2)) | ||
|
|
||
| conn = Net::LDAP::Connection.new(socket: mock) | ||
| results = [] | ||
| conn.search(base: "dc=test", size: 3, paged_searches_supported: true) { |e| results << e } | ||
|
|
||
| # With fix: 5 entries >= size 3, stops after page 1 | ||
| # Without fix: would fetch page 2 and get 10 entries | ||
| assert_equal 5, results.size | ||
| assert_equal 1, write_count, "Should stop paging when size limit reached" |
Comment on lines
+514
to
+515
| # When paging is enabled, we set query_limit=0 (no server-side limit) | ||
| # for efficiency, so we must enforce the limit client-side here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Enforce size limit when paged searches are enabled
Fixes the
:sizeoption being ignored when paged searches are enabled and the requested size exceeds 126.Problem
When paging is enabled and remaining entries needed exceeds 126, the code sets
query_limit = 0(no server-side limit) to avoid conflicts with the page size. However, the limit is never enforced client-side.The existing code comment acknowledges this:
Solution
Add a client-side check to break the paging loop when the requested size limit is reached:
Related Issues
nsslapd-sizelimitis 126 #437Testing
Tested against a production LDAP server with 5900+ entries matching the filter.
Before: all 5900+ returned.
After: exactly 3000 as requested.
Checklist
lib/net/ldap/connection.rbbundle exec rake)