PaperMC / PaperMC/Paper

CraftScheduler#parsePending() - Potential Issue with Empty Task Queue

Open
#10,029 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

scope: performance status: input wanted
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Timings or Profile link

is not needed

Description of issue

In CraftScheduler#parsePending() is a possible bug.

If there are no tasks in the queue and therefor head.next() returns null, it will keep the head.

Therefor, it will keep holding the runnable and all objects that it references (including players) leading to potential memory leaks and unwanted consequences.


Details:
It seems like in the above case, both for-loops are not executed once as the conditions are never met.
In the first loop, task is not allowed to be null. But assuming that head.getNext() returns null makes this condition false.
In the next loop we set task = head and execute only if task != lastTask, but lastTask == head and task == head, so lastTask == task and we never execute that for loop as well. Leading us to this.head = lastTask which translates to this.head = this.head.

Plugin and Datapack List

not needed

Server config files

not needed

Paper version

commit-ref: 9223f05a400f63be1cb5700261816960f9cf8391

Other

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating CraftScheduler#parsePending() and tracing the empty-queue path where head.next() returns null. Reproduce or inspect that case, then verify that an empty queue no longer retains the runnable and referenced objects; add or run a focused regression test if the repository provides one.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.