Skip to content

[SPARK-59701][PYTHON][TESTS] Fix flaky test_reap_server_does_not_expire_when_idle_retirement_is_disabled - #58953

Closed
gaogaotiantian wants to merge 1 commit into
apache:masterfrom
gaogaotiantian:fix-local-connect-pool-reap-test-flake
Closed

gaogaotiantian wants to merge 1 commit into
apache:masterfrom
gaogaotiantian:fix-local-connect-pool-reap-test-flake

Conversation

@gaogaotiantian

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Give each subtest iteration of
test_reap_server_does_not_expire_when_idle_retirement_is_disabled its own
_listening_socket() instead of sharing one listener across both iterations.

Why are the changes needed?

_listening_socket() calls listen(1) and never accepts. reap probes reachability via _port_open, which connects and closes without the server ever accepting the connection, so the completed connection keeps occupying the sole backlog slot. With both iterations sharing one listener, the second iteration's connect could not complete, timed out after 0.5s, and is_usable() returned False -- retiring a server that idle retirement was disabled for. This flaked on macOS CI (macos-26-arm64):

FAIL: test_reap_server_does_not_expire_when_idle_retirement_is_disabled (value='-1')
  self.assertEqual(set(self._states(uid)), {"server"})
AssertionError: Items in the first set but not the second: 'retired'

Scoping a fresh listener per iteration matches the single-connect-per-listener pattern the other tests in this suite already use.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing unit test LocalConnectServerPoolUnitTests in pyspark.sql.tests.connect.test_connect_local_server_pool.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Isaac

This pull request and its description were written by Isaac.

…n_idle_retirement_is_disabled

### What changes were proposed in this pull request?

Give each subtest iteration of
`test_reap_server_does_not_expire_when_idle_retirement_is_disabled` its own
`_listening_socket()` instead of sharing one listener across both iterations.

### Why are the changes needed?

`_listening_socket()` calls `listen(1)` and never accepts. `reap` probes
reachability via `_port_open`, which connects and closes without the server
ever accepting the connection, so the connection keeps occupying the sole
backlog slot. With both iterations sharing one listener, the second
iteration's connect could not complete, timed out after 0.5s, and
`is_usable()` returned False -- retiring a server that idle retirement was
disabled for. This flaked on macOS CI.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Existing unit test `LocalConnectServerPoolUnitTests`.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Isaac

Co-authored-by: Isaac <no-reply@databricks.com>
@gaogaotiantian gaogaotiantian changed the title [SPARK-59701][CONNECT] Fix flaky test_reap_server_does_not_expire_when_idle_retirement_is_disabled [SPARK-59701][TESTS] Fix flaky test_reap_server_does_not_expire_when_idle_retirement_is_disabled Sep 21, 2026
@gaogaotiantian

Copy link
Copy Markdown
Contributor Author

@ericm-db hey Eric could you take a look at the test fix and see if it's correct? Thanks!

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-59701][TESTS] Fix flaky test_reap_server_does_not_expire_when_idle_retirement_is_disabled [SPARK-59701][PYTHON][TESTS] Fix flaky test_reap_server_does_not_expire_when_idle_retirement_is_disabled Sep 21, 2026
dongjoon-hyun pushed a commit that referenced this pull request Sep 22, 2026
…e_when_idle_retirement_is_disabled

### What changes were proposed in this pull request?

Give each subtest iteration of
`test_reap_server_does_not_expire_when_idle_retirement_is_disabled` its own
`_listening_socket()` instead of sharing one listener across both iterations.

### Why are the changes needed?

`_listening_socket()` calls `listen(1)` and never accepts. `reap` probes reachability via `_port_open`, which connects and closes without the server ever accepting the connection, so the completed connection keeps occupying the sole backlog slot. With both iterations sharing one listener, the second iteration's connect could not complete, timed out after 0.5s, and `is_usable()` returned `False` -- retiring a server that idle retirement was disabled for. This flaked on macOS CI (`macos-26-arm64`):

```
FAIL: test_reap_server_does_not_expire_when_idle_retirement_is_disabled (value='-1')
  self.assertEqual(set(self._states(uid)), {"server"})
AssertionError: Items in the first set but not the second: 'retired'
```

Scoping a fresh listener per iteration matches the single-connect-per-listener pattern the other tests in this suite already use.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Existing unit test `LocalConnectServerPoolUnitTests` in `pyspark.sql.tests.connect.test_connect_local_server_pool`.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Isaac

This pull request and its description were written by Isaac.

Closes #58953 from gaogaotiantian/fix-local-connect-pool-reap-test-flake.

Authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit b5aa3bd)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@dongjoon-hyun

Copy link
Copy Markdown
Member

Merge Summary:

Posted by merge_spark_pr.py

@gaogaotiantian
gaogaotiantian deleted the fix-local-connect-pool-reap-test-flake branch September 23, 2026 18:19
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.

3 participants