Skip to content

prevent shutdown issues by making server thread daemonic #411

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

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

alexrashed
Copy link
Contributor

Motivation

In the LocalStack test codebase we heavily use LocalStack to test integrations of our emulated AWS services. Thanks for the great project!
In the past we were facing issues with our integration tests timing out due to shutdowns being blocked. It turns out that some of the pytest-httpserver threads were not properly shut down. @bentsku fixed this by patching the HTTPServer class to spawn a deamon thread to make sure that it cannot block the shutdown of the interpreter with localstack/localstack#10052.
This patch broke with the latest release, as the start method was modified (which is why we did not upgrade to the latest version 1.1.2, but introduced an upper limit with localstack/localstack@01a97ba).

This PR aims at fixing these issues upstream to prevent issues like this for other users, as well as to be able to remove the patch in our projects.

Changes

  • Makes the server thread daemonic.
  • Adds a test to ensure that request handlers are executed on daemonic threads.

@csernazs
Copy link
Owner

csernazs commented Apr 9, 2025

Hi @alexrashed ,

Thanks for the PR, it looks good - this thread should not block when the process exits.

Thank you,
Zsolt

@csernazs
Copy link
Owner

csernazs commented Apr 9, 2025

Could you please squash the two commits to one? Precommit bot added a fix to your commit.

@alexrashed alexrashed force-pushed the spawn-daemon-thread branch from e62efdf to b14f3b5 Compare April 9, 2025 15:24
@alexrashed alexrashed force-pushed the spawn-daemon-thread branch from b14f3b5 to 2424568 Compare April 9, 2025 15:26
@csernazs csernazs merged commit 32a25e9 into csernazs:master Apr 9, 2025
10 checks passed
@csernazs
Copy link
Owner

csernazs commented Apr 9, 2025

Thanks! I'll do a release soon and let you know about it.

@alexrashed alexrashed deleted the spawn-daemon-thread branch April 9, 2025 16:15
csernazs added a commit that referenced this pull request Apr 10, 2025
csernazs added a commit that referenced this pull request Apr 10, 2025
csernazs added a commit that referenced this pull request Apr 10, 2025
csernazs added a commit that referenced this pull request Apr 10, 2025
@csernazs
Copy link
Owner

hi @alexrashed,

Version 1.1.3 has just been released with your fix. Please give it a try if you can.

Thanks again for your contribution,
Zsolt

@alexrashed
Copy link
Contributor Author

This is great, thanks a lot for merging the PR and creating a release! 🥳

zifeo pushed a commit to zifeo/dataconf that referenced this pull request May 1, 2025
Bumps [pytest-httpserver](https://github.com/csernazs/pytest-httpserver)
from 1.1.2 to 1.1.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/csernazs/pytest-httpserver/releases">pytest-httpserver's
releases</a>.</em></p>
<blockquote>
<h2>1.1.3</h2>
<ul>
<li>Run server threads with daemon flag, preventing shutdown issues. <a
href="https://redirect.github.com/csernazs/pytest-httpserver/issues/411">#411</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/csernazs/pytest-httpserver/blob/master/CHANGES.rst">pytest-httpserver's
changelog</a>.</em></p>
<blockquote>
<h1>1.1.3</h1>
<p>.. _Release Notes_1.1.3_Bug Fixes:</p>
<h2>Bug Fixes</h2>
<ul>
<li>Run server threads with daemon flag, preventing shutdown issues.
<code>[#411](csernazs/pytest-httpserver#411)
&lt;https://github.com/csernazs/pytest-httpserver/pull/411&gt;</code>_</li>
</ul>
<p>.. _Release Notes_1.1.2:</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/68b7ce56d640a9e40c03c7c914cead6193c84bc8"><code>68b7ce5</code></a>
CHANGES.rst: add release notes for 1.1.3</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/7ae4709662e71d35e53c86930a3acda3cb8baf88"><code>7ae4709</code></a>
Version bump to 1.1.3</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/a00d8a4a20029ce651bb9a99226747fbbd528268"><code>a00d8a4</code></a>
releasenotes: add release note for <a
href="https://redirect.github.com/csernazs/pytest-httpserver/issues/411">#411</a></li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/e9010dc0a42331a075828929d794944e57364157"><code>e9010dc</code></a>
[pre-commit.ci] pre-commit autoupdate</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/32a25e95dcc09a87a28036c8de3da55b1a17a4b6"><code>32a25e9</code></a>
explicitly spawn daemon thread for http server</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/414173b8d22b92c32f8a294bf999909954713009"><code>414173b</code></a>
build(deps-dev): bump the deps group with 5 updates</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/5acead44e5df4902b502e14a4e4b15e5b93b0061"><code>5acead4</code></a>
[pre-commit.ci] pre-commit autoupdate</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/97dba58fb28597762a2eba794ba4489e14aa2fdb"><code>97dba58</code></a>
[pre-commit.ci] pre-commit autoupdate</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/a0da3951da3763566761195c05891f967e3bc0d5"><code>a0da395</code></a>
[pre-commit.ci] pre-commit autoupdate</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/178ded6de4b0aa9d5138d72124341fdcb289f19a"><code>178ded6</code></a>
[pre-commit.ci] pre-commit autoupdate</li>
<li>Additional commits viewable in <a
href="https://github.com/csernazs/pytest-httpserver/compare/1.1.2...1.1.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pytest-httpserver&package-manager=pip&previous-version=1.1.2&new-version=1.1.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

2 participants