superset: Asynchronous query execution sometimes stuck in PENDING status

Bug description

I encountered the following issue: all ASYNC queries are PENDING.

The log shows that the queries are passed to the workers but do not return.

superset[3920984]: Triggering query_id: 58629
superset[3920984]: 2024-06-28 15:25:08,876:INFO:superset.commands.sql_lab.execute:Triggering query_id: 58629
superset[3920984]: Query 58629: Running query on a Celery worker
superset[3920984]: 2024-06-28 15:25:08,886:INFO:superset.sqllab.sql_json_executer:Query 58629: Running query on a Celery worker
superset[3920984]: Triggering query_id: 58630
superset[3920984]: 2024-06-28 15:25:10,448:INFO:superset.commands.sql_lab.execute:Triggering query_id: 58630
superset[3920984]: Query 58630: Running query on a Celery worker
superset[3920984]: 2024-06-28 15:25:10,456:INFO:superset.sqllab.sql_json_executer:Query 58630: Running query on a Celery worker

How to reproduce the bug

Allow using Asynchronous query execution in database. When there a heavy load the queries get stuck in PENDING status.

Screenshots/recordings

image

Superset version

4.0.1

Python version

3.11

Node version

I don’t know

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn’t find a solution to my problem.
  • I have searched the GitHub issue tracker and didn’t find a similar bug report.
  • I have checked Superset’s logs for errors and if I found a relevant Python stacktrace, I included it here as text in the “additional context” section.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

To resolve the caching issue in Celery, ensure that your Redis configuration is correctly set up in superset_config.py. Here is a sample configuration that uses Redis for both Celery and caching:

import os

REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
REDIS_PORT = os.getenv("REDIS_PORT", "6379")
REDIS_CELERY_DB = os.getenv("REDIS_CELERY_DB", "0")
REDIS_RESULTS_DB = os.getenv("REDIS_RESULTS_DB", "1")
REDIS_CACHE_DB = os.getenv("REDIS_CACHE_DB", "4")

CACHE_CONFIG = {
    "CACHE_TYPE": "RedisCache",
    "CACHE_DEFAULT_TIMEOUT": 300,
    "CACHE_KEY_PREFIX": "superset_",
    "CACHE_REDIS_URL": f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CACHE_DB}",
}
DATA_CACHE_CONFIG = CACHE_CONFIG

class CeleryConfig:
    broker_url = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}"
    imports = ("superset.sql_lab", "superset.tasks.thumbnails")
    result_backend = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_RESULTS_DB}"
    worker_prefetch_multiplier = 1
    task_acks_late = False
    beat_schedule = {
        "reports.scheduler": {
            "task": "reports.scheduler",
            "schedule": crontab(minute="*", hour="*"),
        },
        "reports.prune_log": {
            "task": "reports.prune_log",
            "schedule": crontab(minute=10, hour=0),
        },
    }

CELERY_CONFIG = CeleryConfig

Ensure that the environment variables REDIS_HOST, REDIS_PORT, REDIS_CELERY_DB, REDIS_RESULTS_DB, and REDIS_CACHE_DB are correctly set in your environment. This configuration uses Redis for both the Celery result backend and the cache backend, which should resolve any caching issues related to Celery [1][2].

Additionally, make sure you have the necessary dependencies installed for Redis caching:

pip install redis

If the issue persists, check the Celery worker logs for any specific error messages related to caching. These logs can provide more details about the problem [3].

To continue talking to Dosu, mention @dosu.

To resolve the PermissionError: [Errno 13] Permission denied: 'geckodriver.log', you need to ensure that the user running the WebDriver has the necessary permissions to write to the directory where geckodriver.log is being created.

You can set the environment variable GECKODRIVER_LOG to a directory where the user has write permissions. Here is an example of how to do this in your Python script:

import os
from selenium import webdriver

# Set the environment variable for geckodriver log path
os.environ['GECKODRIVER_LOG'] = '/path/to/logs/geckodriver.log'

options = webdriver.FirefoxOptions()
options.headless = True  # Run in headless mode if needed

driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver', options=options)

Make sure to replace /path/to/logs/ with a directory path where the user has write permissions. This will ensure that the geckodriver.log file can be created without any permission issues.

To continue talking to Dosu, mention @dosu.

NICE! RESOLVED

REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
REDIS_PORT = os.getenv("REDIS_PORT", "6379")
REDIS_CELERY_DB = os.getenv("REDIS_CELERY_DB", "2")
REDIS_RESULTS_DB = os.getenv("REDIS_RESULTS_DB", "3")
REDIS_CACHE_DB = os.getenv("REDIS_CACHE_DB", "4")

# Redis Caching
CACHE_CONFIG = {
    "CACHE_TYPE": "RedisCache",
    "CACHE_DEFAULT_TIMEOUT": 900,
    "CACHE_KEY_PREFIX": "superset_results",
    "CACHE_REDIS_URL": f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CACHE_DB}",
}
DATA_CACHE_CONFIG = CACHE_CONFIG

# Long running query handling using Celery workers
class CeleryConfig(object):
    broker_url = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}"
    imports = ("superset.sql_lab", "superset.tasks.thumbnails")
    result_backend = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_RESULTS_DB}"
    CELERYD_LOG_LEVEL = 'DEBUG'
    CONCURRENCY = 1

CELERY_CONFIG = CeleryConfig

# Persisting results from running query handling using Celery workers
from cachelib.redis import RedisCache
RESULTS_BACKEND = RedisCache(host='localhost', port=6379, key_prefix='superset_results')

To resolve the issue with Selenium Manager failing to obtain the geckodriver, you can manually download and install the geckodriver and ensure that it is accessible in your system’s PATH. Here are the steps:

  1. Download Geckodriver: Download the appropriate version of geckodriver for your system from the official geckodriver releases page.

    wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
    
  2. Extract the Geckodriver: Extract the downloaded tar file.

    tar -xvzf geckodriver-v0.34.0-linux64.tar.gz
    
  3. Move Geckodriver to a Directory in PATH: Move the extracted geckodriver to a directory that is in your system’s PATH, such as /usr/local/bin.

    sudo mv geckodriver /usr/local/bin/
    
  4. Verify Installation: Verify that geckodriver is installed and accessible.

    geckodriver --version
    
  5. Update Superset Configuration: Ensure that your Superset configuration is set to use the geckodriver. Update your superset_config.py to specify the path to the geckodriver if necessary.

    from selenium import webdriver
    
    options = webdriver.FirefoxOptions()
    options.headless = True  # Run in headless mode if needed
    
    driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver', options=options)
    

By manually installing the geckodriver and ensuring it is in your PATH, you should be able to avoid the timeout issue with Selenium Manager and successfully generate thumbnails using Celery in Superset [1].

To continue talking to Dosu, mention @dosu.

To resolve the timeout issue when trying to fetch the latest geckodriver release from GitHub using Celery, you can try increasing the timeout settings in your Celery configuration. Specifically, you can adjust the SCREENSHOT_LOCATE_WAIT and SCREENSHOT_LOAD_WAIT settings in your superset_config.py file.

Here is an example configuration:

SCREENSHOT_LOCATE_WAIT = 200  # Increase the wait time for locating elements
SCREENSHOT_LOAD_WAIT = 1200   # Increase the wait time for loading the page

These settings will give more time for the geckodriver to fetch and load the necessary resources, potentially resolving the timeout issue [1].

To continue talking to Dosu, mention @dosu.

To resolve the timeout error when trying to fetch the latest geckodriver release from GitHub, you can increase the timeout duration for the wget command. Modify the wget command in your Dockerfile to include the --timeout option with a higher value.

Here is the modified section of the Dockerfile:

# Install GeckoDriver WebDriver
ARG GECKODRIVER_VERSION=v0.34.0 \
    FIREFOX_VERSION=125.0.3
RUN apt-get update -qq \
    && apt-get install -yqq --no-install-recommends wget bzip2 \
    && wget --timeout=60 -q https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -O - | tar xfz - -C /usr/local/bin \
    # Install Firefox
    && wget --timeout=60 -q https://download-installer.cdn.mozilla.net/pub/firefox/releases/${FIREFOX_VERSION}/linux-x86_64/en-US/firefox-${FIREFOX_VERSION}.tar.bz2 -O - | tar xfj - -C /opt \
    && ln -s /opt/firefox/firefox /usr/local/bin/firefox \
    && apt-get autoremove -yqq --purge wget bzip2 && rm -rf /var/[log,tmp]/* /tmp/* /var/lib/apt/lists/*

This sets the timeout for wget to 60 seconds, which should help mitigate timeout issues. Adjust the timeout value as needed based on your network conditions [1].

To continue talking to Dosu, mention @dosu.

@rusackas, I forgot to restart the service after upgrading the configurations. ^^

Your configuration for Redis caching and Celery workers looks correct. Here are a few additional steps to ensure everything is set up properly:

  1. Verify Redis Server: Ensure that the Redis server is running and accessible. You can check the Redis server status by running:

    redis-cli ping
    

    The response should be PONG.

  2. Check Celery Worker Logs: Look for any errors or warnings in the Celery worker logs. These logs can provide insights into why the queries might be getting stuck in the PENDING status. You can start a Celery worker with the following command and monitor the logs:

    celery --app=superset.tasks.celery_app:app worker --loglevel=info
    
  3. Celery Beat: Ensure that Celery Beat is running if you have scheduled tasks. Start it with:

    celery --app=superset.tasks.celery_app:app beat --loglevel=info
    
  4. Async Query Execution: Ensure that the ASynchronousSqlJsonExecutor class is properly handling the execution of async queries. The execute method should be correctly implemented to start the query on a Celery worker and handle any exceptions that may occur [1].

  5. Frontend Handling: Ensure that the frontend is correctly handling the async events. The asyncEvent.ts file in the Superset frontend middleware is responsible for managing async events, including polling and WebSocket connections to handle async query statuses [2].

  6. Known Issues: There is a known issue in the superset-helm-chart-0.12.11 version that could affect the execution of asynchronous queries. This issue has been addressed in a fix, so ensure you are using the latest version or have applied the necessary patches [3].

By following these steps, you should be able to identify and resolve the issue causing asynchronous queries to get stuck in the PENDING status.

To continue talking to Dosu, mention @dosu.