Skip to content

Can't Catch Error in Dramatiq worker and crashing the MainThread #227

Description

@jrusso1020

Issues

GitHub issues are for bugs. If you have questions, please ask them on the discussion board.

Checklist

  • Does your title concisely summarize the problem?
  • Did you include a minimal, reproducible example?
  • What OS are you using?
  • What version of Dramatiq are you using?
  • What did you do?
  • What did you expect would happen?
  • What happened?

What OS are you using?

macOS 10.14.5

What version of Dramatiq are you using?

1.6.1

What did you do?

While running a dramatiq actor that involves querying an elastic search instance on AWS a critical error occurs causing the dramatiq MainThread to crash. I try to catch the error in the worker as well as around the piece of code I believe is crashing but I am unable to catch the exception and therefore unable to tell what exactly is happening. I have checked that the environment variables are set correctly.

The code works when I perform a local query to elasticsearch on my computer, but it fails when trying to query a Elasticsearch cluster on AWS. However, I am able to run the code in the python terminal. It just fails in the dramatiq worker

@dramatiq.actor
def worker():
    import os
    from elasticsearch_dsl import Search
    from elasticsearch import Elasticsearch, RequestsHttpConnection
    from requests_aws4auth import AWS4Auth
    index = os.getenv('ELASTIC_SEARCH_INDEX')
    host = os.getenv('ELASTIC_SEARCH_HOST')
    awsauth = AWS4Auth(os.getenv('AWS_ACCESS_KEY'), os.getenv('AWS_SECRET_KEY'), os.getenv('AWS_REGION'), 'es')
    es = Elasticsearch(
        hosts=[{'host': host, 'port': 443}],
        http_auth=awsauth,
        use_ssl=True,
        verify_certs=True,
        connection_class=RequestsHttpConnection
    )
    logger.info('got here')
    try:
        logger.info("es.info {}".format(es.info()))
    except Exception as err:
        logger.info(err)

What did you expect would happen?

I would expect to be able to catch the exception or at least have the exception surfaced by dramatiq so that I can see what is happening and debug it. If I was able to see what exception/error was occuring that would help me know what is going wrong when trying to access the AWS elasticsearch cluster

What happened?

Received the following critical logging message, and then the MainThread is shut down killing all dramatiq workers

13:25:32 worker.1   | 2019-09-16 13:25:32,309 [MainThread  ] [CRITI]  Worker with PID 34475 exited unexpectedly (code -11). Shutting down...

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions