Skip to content

Commit

Permalink
feat: debug stuck process by sending SIGUSR1 (backport #25502) (#25527)
Browse files Browse the repository at this point in the history
* fix: debug stuck process by sending SIGUSR1

It will print stack to stderr.

(cherry picked from commit 6560d45)

* fix: set sane default timeout on SMTP

(cherry picked from commit fdd74e3)

[skip ci]

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 19, 2024
1 parent 01cca38 commit 6c8cc5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions frappe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
Read the documentation: https://frappeframework.com/docs
"""
import copy
import faulthandler
import functools
import gc
import importlib
import inspect
import json
import os
import re
import signal
import traceback
import unicodedata
import warnings
Expand Down Expand Up @@ -263,6 +265,7 @@ def init(site: str, sites_path: str = ".", new_site: bool = False, force=False)
if not _qb_patched.get(local.conf.db_type):
patch_query_execute()
patch_query_aggregation()
_register_fault_handler()

setup_module_map(include_all_apps=not (frappe.request or frappe.job or frappe.flags.in_migrate))

Expand Down Expand Up @@ -2459,6 +2462,10 @@ def wrapper(*args, **kwargs):
return wrapper


def _register_fault_handler():
faulthandler.register(signal.SIGUSR1)


from frappe.utils.error import log_error

if _tune_gc:
Expand Down
8 changes: 5 additions & 3 deletions frappe/email/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License: MIT. See LICENSE

import smtplib
from contextlib import suppress

import frappe
from frappe import _
Expand Down Expand Up @@ -71,7 +72,7 @@ def session(self):
SMTP = smtplib.SMTP_SSL if self.use_ssl else smtplib.SMTP

try:
_session = SMTP(self.server, self.port)
_session = SMTP(self.server, self.port, timeout=2 * 60)
if not _session:
frappe.msgprint(
_("Could not connect to outgoing email server"), raise_exception=frappe.OutgoingEmailError
Expand Down Expand Up @@ -122,8 +123,9 @@ def is_session_active(self):
return False

def quit(self):
if self.is_session_active():
self._session.quit()
with suppress(TimeoutError):
if self.is_session_active():
self._session.quit()

@classmethod
def throw_invalid_credentials_exception(cls):
Expand Down

0 comments on commit 6c8cc5c

Please sign in to comment.