Skip to content

psycopg2.InterfaceError: connection already closed #15850

Closed

Description

Describe the bug
psycopg2.InterfaceError: connection already closed.

Exception or Stack Trace
2020-12-03T00:06:41.150453788Z psycopg2.OperationalError: SSL SYSCALL error: EOF detected
2020-12-03T00:06:41.150457488Z
2020-12-03T00:06:41.150460788Z
2020-12-03T00:06:41.150464188Z The above exception was the direct cause of the following exception:
2020-12-03T00:06:41.150467888Z
2020-12-03T00:06:41.150471088Z Traceback (most recent call last):
2020-12-03T00:06:41.150474588Z File "/home/site/wwwroot/backend_api/pre_model_scheduler.py", line 56, in start_pre_model_scheduler
2020-12-03T00:06:41.150478088Z handle_expired_documents()
2020-12-03T00:06:41.150481688Z File "/home/site/wwwroot/backend_api/pre_model_scheduler.py", line 39, in handle_expired_documents
2020-12-03T00:06:41.150485188Z documents_to_resend = check_status_in_db()
2020-12-03T00:06:41.150488588Z File "/home/site/wwwroot/backend_api/pre_model_scheduler.py", line 32, in check_status_in_db
2020-12-03T00:06:41.150492188Z if res:
2020-12-03T00:06:41.150502488Z File "/antenv/lib/python3.7/site-packages/django/db/models/query.py", line 272, in bool
2020-12-03T00:06:41.150516188Z self._fetch_all()
2020-12-03T00:06:41.150519688Z File "/antenv/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _fetch_all
2020-12-03T00:06:41.150522988Z self._result_cache = list(self._iterable_class(self))
2020-12-03T00:06:41.150526088Z File "/antenv/lib/python3.7/site-packages/django/db/models/query.py", line 54, in iter
2020-12-03T00:06:41.150529288Z results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
2020-12-03T00:06:41.150532388Z File "/antenv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
2020-12-03T00:06:41.150535588Z cursor.execute(sql, params)
2020-12-03T00:06:41.150538688Z File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
2020-12-03T00:06:41.150541888Z return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
2020-12-03T00:06:41.150544988Z File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
2020-12-03T00:06:41.150548188Z return executor(sql, params, many, context)
2020-12-03T00:06:41.150551288Z File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
2020-12-03T00:06:41.150554388Z return self.cursor.execute(sql, params)
2020-12-03T00:06:41.150557388Z File "/antenv/lib/python3.7/site-packages/django/db/utils.py", line 89, in exit
2020-12-03T00:06:41.150562188Z raise dj_exc_value.with_traceback(traceback) from exc_value
2020-12-03T00:06:41.150565488Z File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
2020-12-03T00:06:41.150568588Z return self.cursor.execute(sql, params)
2020-12-03T00:06:41.150571588Z django.db.utils.OperationalError: SSL SYSCALL error: EOF detected

To Reproduce
Create a PostgreSQL database in Azure.
Create a Django App (we are using Django == 2.2) on your local machine.
Use the requirements.txt file that is attached to have all of our project dependencies. (if I need to be more specific for you to understand how to use and modify settings please let me know)
In the settings.py file update the DATABASES default settings to your PostgreSQL settings. (USER, HOST, etc.)
You can set one or two endpoints (in the views.py file) in order to test the app after deployment.
Create a python-based Azure Web App.
Deploy the app to Azure Web App. (we are using CI/CD with Local Git)
Add the attached scheduler file to the main folder. (Based on Django layout it is the folder where the apps.py file is in)
In apps.py file in ready() function add the below lines -

  •      from < THE_NAME_OF_THE_DJANGO_PROJECT > import pre_model_scheduler
    
  •      pre_model_scheduler.start()
    

Create a table in the database and modify line 28 in pre_model_scheduler.py accordingly.
(You can see in the pre_model_scheduler.py file that we are referring to the Documents table by using the Django ORM.)

Code Snippet
Add the code snippet that causes the issue.

def check_status_in_db():
    """checks in database for pre-model data that has not been updated for x hours"""
    # get data older than the time threshold
    documents_to_resend = []
    time_threshold = datetime.datetime.now() - timedelta(hours=MAX_TIME_AS_PRE_MODEL)
    res = Documents.objects.filter(document_status="pre-model", source__in=[Source.WEB, Source.EMAIL],
                                   upload_date__lt=time_threshold)
    if res:
        documents_to_resend = [{"document_id": r.document_id, "company_id": r.company_id} for r in res]
    return documents_to_resend

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • Python Version: Python 3.7
  • azure-servicebus==0.50.2
  • Django 2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.PostgreSQLWeb Appscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-author-feedbackWorkflow: More information is needed from author to address the issue.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions