Skip to content

Backport: make WEBrick test teardown block until the server thread exits (#165) - #168

Merged
donoghuc merged 1 commit into
logstash-plugins:5.xfrom
donoghuc:backport-webrick-teardown-5.x
Nov 4, 2026
Merged

donoghuc merged 1 commit into
logstash-plugins:5.xfrom
donoghuc:backport-webrick-teardown-5.x

Conversation

@donoghuc

Copy link
Copy Markdown
Contributor

Backport of #165 to 5.x. Spec-only change.

Fixes #166

…ash-plugins#165)

The flaky HTTP output specs were starting WEBrick on a background thread and tearing it down asynchronously, which could leave the listener alive between examples and hang retries against a server that had not fully stopped.

- **Return the WEBrick thread from the shared test helper**
  - `start_app_and_wait` now returns both the server instance and the thread running `app.start!`
  - this gives teardown a reliable handle for waiting until WEBrick has actually exited

- **Add a blocking teardown helper**
  - introduced `stop_app_and_wait(app, server, server_thread)`
  - shutdown order is now:
    1. `app.stop!`
    2. `server.shutdown`
    3. `server_thread.join(30)`
  - if shutdown does not complete within the bound, the helper emits a clear warning and kills the thread instead of silently hanging

- **Update the existing spec call sites**
  - both the main HTTP spec setup and the TLS-specific setup now capture `@server_thread`
  - both teardown paths now use the shared blocking helper instead of manually shutting down WEBrick

```ruby
@server, @server_thread = start_app_and_wait(TestApp)

stop_app_and_wait(TestApp, @server, @server_thread)
```

Co-authored-by: donoghuc <15354214+donoghuc@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Changelog and Version Management

No changelog or version changes detected. You can either update them manually or use a comment command to update them automatically on merge:

/pr_prepare release:<patch|minor|major> — bump version + update changelog
/pr_prepare changelog:add — changelog entry only (no version bump)

/pr_prepare release:patch
- Add the changelog entry here
  - (Additional details can be provided in multiple lines, respecting markdown formatting)

Omit the entry line to use the PR title. If multiple commands are posted, the last one wins.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The TLS helper can return before a killed server thread exits, allowing the next example to race with teardown on the shared port.

1 open issue
What changed in this PR

Backports #165 to the 5.x branch to address flaky WEBrick teardown in the HTTP output specs, as requested in #166. Changes are limited to specs.

Changes:

  • Return the server thread alongside the server instance from the startup helper.
  • Add shared teardown that waits up to 30 seconds, then warns and kills the thread on timeout.
  • Update HTTP and TLS specs to use the shared teardown helper.
File Description
spec/​spec_helper.rb Track the server thread and add blocking teardown with a timeout fallback.
spec/​outputs/​http_spec.rb Capture thread handles and use shared teardown in HTTP and TLS specs.

Review effort: Balanced

Comment thread spec/spec_helper.rb

unless server_thread.join(30)
warn "Timed out waiting for test server thread to stop"
server_thread.kill

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be solved by a join, but it is not a big deal since it would only affect the timeout path

@donoghuc
donoghuc merged commit 32c252e into logstash-plugins:5.x Nov 4, 2026
13 checks passed
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.

4 participants