Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InvalidStateError in manager.py#in_pending_state caused by race condition #967

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

a3626a
Copy link

@a3626a a3626a commented Sep 4, 2023

Background

In my jupyter system, kernel start, restart and shutdown are relatively frequent, comparing to other environment. It is due to additional features like online judge.

In this environment, Sentry reported InvliadStateError. It is very common error, occurs hundreds times a day.
image

Introduction

in_pending_state is a decorator on async functions. If someone invokes a decorated function, .ready is instantiated and finishes(done) after the function invokation.

I think we can isolate in_pending_state from kernel management, and consider this as a general coroutine management service.

  • if any "in pending state" function is executing, it is "in pending state"
  • .ready is a coroutine that instantiated when it becomes pending, and finished when it becomes ready(=not pending)

The Problem and The Solution

Original implementation does not consider multiple executing functions. So the implementation can cause a single .ready coroutine to set_result twice. This causes InvalidStateError. I have coded a simple test case for this.

To fix this, more general mechanism is needed. Additionally, we don't have to associate this mechanism to kernel lifecycle. Previous ._attempted_start adds unnecessary coupling to the code. Therefore I isolated the mechanism from the details of the decorated function, so introduced ._ready_count and removed .attempted_start.

Help Needed

However, I'm not sure about how to associate this new mechanism with owns_kernel.

Might be related

jupyter-server/jupyter_server#1247

@a3626a a3626a changed the title Fix InvalidStateError in manager.py#in_pending_state cause by race condition Fix InvalidStateError in manager.py#in_pending_state caused by race condition Sep 4, 2023
@krassowski krassowski added the bug label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants