Skip to content

Conversation

@thrau
Copy link
Member

@thrau thrau commented Mar 6, 2024

Motivation

I noticed log lines in the builds during shutdown

'Thread' object has no attribute 'stop'
'Thread' object has no attribute 'stop'
...

After some digging, I found that our new stepfunctions provider is putting plain python threads into TMP_THREADS that don't have a stop attribute. This PR doesn't fix this problem, but it improves error logging during shutdown for these types of issues.
While doing that, I noticed that those stepfunction threads aren't daemon threads, and may potentially be blocking the shutdown, so I added specific logging for that as well.

I also noticed that FuncThread sets self.daemon = True, but it's never passed to the constructor which does some additional setup to create a daemonic thread.

Changes

  • FuncThread instances are now properly instantiated as daemon threads
  • the thread cleanup procedure now does better debug logging

@thrau thrau requested a review from dominikschubert March 6, 2024 14:57
@thrau thrau added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Mar 6, 2024
@thrau thrau mentioned this pull request Mar 6, 2024
7 tasks
Copy link
Member

@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

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

LGTM, looks safe to me. Appreciate the new logging, just added minor nits/suggestions to make the wording a bit clearer

Comment on lines +130 to +132
LOG.warning(
"[shutdown] Non-daemon thread %s may block localstack shutdown", thread
)
Copy link
Member

Choose a reason for hiding this comment

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

👍 love the warning

thread.stop(quiet=quiet)
except Exception as e:
print(e)
LOG.debug("[shutdown] Error stopping thread %s: %s", thread, e)
Copy link
Member

Choose a reason for hiding this comment

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

might the stack trace be interesting for us as well? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

given we only had a print statement so far, lets see how far we get :D

)
else:
threading.Thread.__init__(self)
threading.Thread.__init__(self, daemon=daemon)
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch, definitely clearer that way.

Not sure if that actually caused issues though since using the setter is also part of the official API. Only difference in behavior should be the inheritance of the daemon state when passing None.

@github-actions
Copy link

github-actions bot commented Mar 6, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 30m 21s ⏱️ + 5m 13s
2 691 tests ±0  2 435 ✅ ±0  256 💤 ±0  0 ❌ ±0 
2 693 runs  ±0  2 435 ✅ ±0  258 💤 ±0  0 ❌ ±0 

Results for commit 5ef43fb. ± Comparison against base commit f3c2b4b.

Co-authored-by: Dominik Schubert <dominik.schubert91@gmail.com>
@thrau thrau merged commit 87f747f into master Mar 6, 2024
@thrau thrau deleted the fix-thread-utils branch March 6, 2024 16:22
@coveralls
Copy link

coveralls commented Mar 6, 2024

Coverage Status

coverage: 85.881% (+0.001%) from 85.88%
when pulling 15d676e on fix-thread-utils
into f3c2b4b on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants