Closed JackAtOmenApps closed 1 year ago
Update: I saw in these comments that suggest that version 1.18.8 probably wouldn't fix my issue and 1.18.7 has its own issues. So I reverted to 1.18.6, which seems to be working alright. The shell
and shell_plus
commands now work as expected and I'm not noticing any other issues yet. So it seems changes in 1.18.7/1.18.8/1.18.9 are at fault.
Well, I may be just going insane at this point.
Everything was great with 1.18.6 for the past 8 hours. And now I get essentially the same error trace.
Very sad. Going to sleep.
Hi @OmenApps. Thanks for raising this. We are actively working on a fix for this internally. Thank you for your patience. We will update the issue when we are ready for you to test the new package.
@OmenApps You are not alone. After maybe days of trying to figure out why all our Django deployments died all of a sudden, and isolating multiple libraries until the error was isolated, I realized that it was this library the one responsible. I'll share my configuration as well here.
@shawkinsmezmo Sorry to duplicate the issue and post in this one instead of #79 , but this is more ad-hoc to the problem we are facing.
This is how the logging section of our configuration file looks like:
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"logdna": {
"level": "DEBUG",
"class": "logdna.LogDNAHandler",
"key": os.environ.get("LOGDNA_INGESTION_KEY"),
"options": {
"app": "...",
"hostname": f"...",
"env": get_secret("ENVIRONMENT"),
"index_meta": True,
"tags": ["..."],
},
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
},
},
"loggers": {
"logdna": {"handlers": ["logdna", "console"], "propagate": True},
},
}
I have to say also that two days ago I had the exact same error as @OmenApps apps above (threading/lock
). But today, upon trying again I couldn't get that error, but any django command that we run still hangs
@auirarrazaval We've identified that there is a problem with the recent changes that specifically affects Django, and possibly other third party libraries / frameworks that instantiate and close multiple instances of the same log handler class during the course of an application's lifecycle. We have a PR that we are testing / promoting internally that should address this. I apologize for the inconvenience and appreciate your patience while we sort this out. Part of this change will include beefing up our internal testing to make sure that we cover additional usages, such as Django and other common / popular middlewares.
Hi @OmenApps, @auirarrazaval - Can you give the latest package a try and let me know if it resolves your issues? Thanks!
@shawkinsmezmo I have just tried against v1.18.11 and manage.py runserver
is still hanging in Django
@auirarrazaval Interesting. I was able to reproduce this with the help of your configuration. Thanks for sharing that. Currently debugging things and will report back when I have a fix.
@shawkinsmezmo Thanks! I wish I could give better insights, but right now it just seems to hang with no messages (i even tried setting a high verbosity with Django with no success) or tracebacks, so there's not much info. Maybe telling you my environment will help: OS: Ubuntu 20.04 Python: 3.9.16
And here is my pip freeze:
annotated-types==0.5.0
asgiref==3.7.2
attrs==23.1.0
boto3==1.28.12
botocore==1.31.12
certifi==2023.7.22
cfgv==3.3.1
charset-normalizer==3.2.0
distlib==0.3.7
Django==4.2.3
django-cors-headers==4.2.0
djangorestframework==3.14.0
drf-yasg==1.21.7
filelock==3.12.2
fuzzywuzzy==0.18.0
identify==2.5.26
idna==3.4
inflection==0.5.1
jmespath==1.0.1
jsonschema==4.18.4
jsonschema-specifications==2023.7.1
Levenshtein==0.21.1
logdna==1.18.11
nodeenv==1.8.0
opensearch-py==2.2.0
packaging==23.1
platformdirs==3.9.1
pre-commit==3.3.3
pydantic==2.1.1
pydantic_core==2.4.0
python-dateutil==2.8.2
python-decouple==3.8
python-Levenshtein==0.21.1
pytz==2023.3
PyYAML==6.0.1
rapidfuzz==3.1.2
referencing==0.30.0
requests==2.31.0
rpds-py==0.9.2
s3transfer==0.6.1
sentry-sdk==1.28.1
six==1.16.0
sqlparse==0.4.4
typing_extensions==4.7.1
Unidecode==1.3.6
uritemplate==4.1.1
urllib3==1.26.16
uWSGI==2.0.18
virtualenv==20.24.2
If there's anything that I could do/try on my end I will gladly help
Yep, same here. v1.18.11 still hangs. Rolling back again to v1.18.6 for the time being.
@OmenApps @auirarrazaval OK. I was able to trace the issue to a single line of code, based on the config that you provided. I'm working on shepherding another fix out. I'll update when it's out. Thanks for your patience guys.
@OmenApps @auirarrazaval Can you guys give version 1.18.12
a try and let me know how it goes? I think I found the root cause of all of these issues, and it's that the logdna handler implementation was overwriting a variable of the base logging.Handler
class
@shawkinsmezmo So far so good. With v1.18.12 I am able to use the shell and so far everything seems to be working correctly.
@shawkinsmezmo Same here! I was able to run the server locally without any issues. Tomorrow I hope to be doing a staging deployment and keep you updated
@shawkinsmezmo seems to be working fine in deployments as well. Thanks for your help!
@auirarrazaval glad to hear it! I'll keep this issue open for another day or so in case folks run into any more issues, but otherwise I'm feeling optimistic that we finally have this licked.
Closing this issue as resolved.
The Problem
I've spent half the day trying to identify an issue, and it looks like it may be due to logdna. I see that there are similar issues in #103 and #79.
For us, django itself is working, but running ipython via the django
shell
orshell_plus
(with django_extensions) commands hangs forever until killing withCTRL+c
.My setup:
Example Error Traces
Running either of these:
docker compose -f docker-compose.remote.yml exec django python manage.py shell
(default is set to ipython)docker compose -f docker-compose.remote.yml exec django python manage.py shell -i ipython
Results in:
Running this:
docker compose -f docker-compose.remote.yml exec django python manage.py shell_plus
Results in:
Both of the traces above are the same with the exception of lines specific to use of the
shell
vsshell_plus
commands.Running either of these, which use a plain python shell rather than ipython, works fine:
docker compose -f docker-compose.remote.yml exec django python manage.py shell -i python
docker compose -f docker-compose.remote.yml exec django python manage.py shell_plus --plain
Also, running ipython on its own works fine:
docker compose -f docker-compose.remote.yml exec django ipython --version
outputs 8.14.0docker compose -f docker-compose.remote.yml exec django ipython --log-level=DEBUG
Runs ipython via the django container (but not incorporating the django project itself) just fineMore details
I did a bunch of troubleshooting looking at recent code changes and issues in the traitlets, ipython, django packages and others. Eventually I narrowed it down to a logging issue.
Removed all logging by setting
LOGGING_CONFIG = False
and the shell works just fine.Began adding logging configuration to django's
LOGGING
dict bit by bit until I hit upon the issue, which appears to be the moment I add logdna back to the mix. To be clear, I've been using logdna/mezmo for a long time without issues, so I'm confident the issue isn't in my logging config, but in a recent change to the logdna package.My logging config in django settings:
I'm curious is anyone else has experienced these symptoms. I hadn't noticed there was a problem until I tried to get into the shell this morning. None of my existing tests had highlighted this problem. I guess I should add one that runs the
shell
command when I make updates to dependencies 🤔