#4052·Nuitka

Nuitka --onefile runtime crash with Kurigram ≥2.2.21

Author: GentlespriteCreated Sep 21, 2026Updated Sep 25, 2026
Labelsbugfactoryexcellent_report

Bug Description

I am encountering a reproducible runtime crash when compiling a Telegram client application with Nuitka.

The application runs correctly with normal CPython, and the same application also works with earlier Kurigram commits. After a specific Kurigram commit, the Nuitka-compiled executable starts failing at runtime.

The important observation is:

  • CPython: works.
  • Nuitka --standalone: works in the tested configuration.
  • Nuitka --onefile: crashes at runtime.
  • The problem is reproducible with Nuitka 2.8.10 and Python 3.11.7.
  • Increasing the executable stack size does not resolve the problem.
  • Removing TgCrypto does not resolve the problem.
  • The first failing Kurigram commit found by bisecting is 15df274030a9d11cc76cbadf5a0b1b9e962d83f1.
  • The immediately preceding tested commit ed4a0ba3b34980f2cdc15e4c4d986b57608c958a works.

This makes the problem appear to be an interaction between Nuitka's compiled runtime and a change in Kurigram's asynchronous Telegram message handling.

The affected application is:

https://github.com/Gentlesprite/Telegram_Restricted_Media_Downloader/tree/8ddfa62bc638f7d6110e230faa37f3e64a935665

After this problem occurred, my project was temporarily replaced with Pyinstaller in subsequent commits, so the above commit (8ddfa62bc638f7d6110e230faa37f3e64a935665) is the last version to use Nuitka.

️ Environment

1. Nuitka Version, Python Version, OS, and Platform

Primary reproduction environment:

  • OS: Windows 10/11 x64
  • Python: 3.11.7
  • Nuitka: 2.8.10
  • Compiler: MSVC
  • Architecture: x64

I have also tested other Nuitka/Python combinations during investigation, including:

  • Nuitka 2.6.7
  • Nuitka 2.8.10
  • Nuitka 4.2.0
  • Nuitka 4.2.1
  • Python 3.11.7
  • Python 3.13.2
  • Python 3.14.3

The specific PyPI names and versions:

tgcrypto
PyYAML
rich==14.2.0
qrcode
pyreadline3
kurigram
pygments
pymediainfo==7.0.1

The exact regression boundary is different depending on the Python version, which suggests that the problem may involve an interaction between the generated code/runtime and the Python version rather than being a simple application-level Python exception.

2. How Nuitka and Python were Installed

Python and Nuitka were installed using the normal Windows Python/pip environment.

The primary reproduction environment uses Python 3.11.7 and Nuitka 2.8.10.

3. Relevant PyPI Packages and Versions

The application uses:

  • Kurigram
  • Pyrogram-derived Telegram client code
  • asyncio
  • Rich
  • TgCrypto

TgCrypto was removed during testing and the crash remained reproducible.

I also tested the relevant configuration without python-socks being the cause.

️ To Reproduce

1. Project Revision

Please use the following exact application revision:

8ddfa62bc638f7d6110e230faa37f3e64a935665

Clone and prepare the project:

bash
git clone https://github.com/Gentlesprite/Telegram_Restricted_Media_Downloader.git
cd Telegram_Restricted_Media_Downloader
git checkout -b my-trmd 8ddfa62bc638f7d6110e230faa37f3e64a935665
python -m pip install -r requirements.txt
python build.py

The project's build.py invokes Nuitka and builds the application using both --standalone and --onefile.

The relevant build configuration includes:

--standalone
--onefile
--msvc=latest
--remove-output
--no-deployment-flag=self-execution
--script-name=main.py

The important point is that python build.py should be used rather than replacing the project's build process with an unrelated Nuitka command.

2. Kurigram Regression Test

I bisected the Kurigram revisions used by the application.

The relevant results on Python 3.11.7 are:

Kurigram commit Result
e62740655fafddbf34a98334d7355f6d13a6e5d4 ✅ Works
1789d5fe6d6795b20e99881a8ae18e1db0171367 ✅ Works
ccb516d2bb44888b7ad5e503cfa42865ed2dc63e ✅ Works
8cbb28e56d9de2c8ac10bcaee390f4f3ab766f8d ✅ Works
ed4a0ba3b34980f2cdc15e4c4d986b57608c958a ✅ Works
15df274030a9d11cc76cbadf5a0b1b9e962d83f1 ❌ Crashes
695dd2a5898bfd51ca9362ce91e6661c6edf0967 ❌ Crashes
cf4c3076cc19ece23d79be478aed39237255230d ❌ Crashes
3f54ad6f1d953402f4a3d3892e1da142d6937367 ❌ Crashes

Therefore:

Last known good:
ed4a0ba3b34980f2cdc15e4c4d986b57608c958a

First known bad:
15df274030a9d11cc76cbadf5a0b1b9e962d83f1

Kurigram 2.2.25 also crashes.

3. Relevant Kurigram Change

The first failing commit is:

15df274030a9d11cc76cbadf5a0b1b9e962d83f1

Its change introduces caching for messages.GetSplitRanges, including a new asynchronous method similar to:

python
self.message_split_ranges = None

async def get_message_split_ranges(self):
    if self.message_split_ranges is None:
        self.message_split_ranges = await self.invoke(
            raw.functions.messages.GetSplitRanges()
        )

    return self.message_split_ranges

This change introduces an additional asynchronous path through Client.invoke().

I am not claiming that this commit itself is necessarily incorrect. However, it is the first Kurigram revision in my bisect that changes the observed result from working to crashing when compiled with Nuitka.

Expected Behavior

The application should run normally after being compiled with Nuitka.

In particular, the Nuitka-compiled executable should behave equivalently to the same application executed directly by CPython.

The working Kurigram revisions demonstrate that the application and its normal asynchronous Telegram workflow can operate correctly in the same environment.

Actual Behavior & Output

The executable starts, but after entering the affected Telegram message-processing path it becomes unresponsive and eventually terminates.

One observed failure is:

Windows fatal exception: code 0xc0000374

which corresponds to:

STATUS_HEAP_CORRUPTION

Another configuration/debugging attempt produces:

-1073741571

which corresponds to:

0xC00000FD
STATUS_STACK_OVERFLOW

The traceback associated with the crash includes the following Kurigram code:

pyrogram/types/user_and_chats/chat.py
    _parse_chat

pyrogram/types/messages_and_media/message.py
    _parse_message

pyrogram/types/messages_and_media/message.py
    _parse

pyrogram/utils.py
    parse_messages

pyrogram/methods/messages/send_message.py
    send_message

The traceback also contains asyncio, ThreadPoolExecutor and Rich Live worker threads.

For example:

Current thread ...

File ".../pyrogram/types/user_and_chats/chat.py", line 1433 in _parse_chat
File ".../pyrogram/types/messages_and_media/message.py", line 1485 in _parse_message
File ".../pyrogram/types/messages_and_media/message.py", line 2264 in _parse
File ".../pyrogram/utils.py", line 144 in parse_messages
File ".../pyrogram/methods/messages/send_message.py", line 30 in send_message
...
File ".../module/bot.py", line 1123 in send_message_to_bot
File ".../module/bot.py", line 987 in start_bot
File ".../module/downloader.py", line 2369 in __download_media_from_links
...

Because the failure occurs in native compiled code, I do not assume that _parse_chat() is necessarily the original source of the corruption. It may simply be where the corrupted state becomes observable.

Additional Debugging

Increasing stack size

I tested increasing the executable stack reserve.

For example:

/STACK:2097152

and also:

/STACK:16777216

Increasing the stack does not solve the problem.

With a larger stack, the program can sometimes run for longer before failing.

In one configuration, the failure changes into a Nuitka runtime assertion:

Assertion failed!

File: .../compiled_frame.h
Line: 157

Expression:
(frame_object)==NULL || Py_REFCNT(frame_object)>0

This suggests that the problem may involve an invalid runtime frame/reference-count state, although I am not claiming this assertion is the root cause.

Removing TgCrypto

I removed TgCrypto and rebuilt the application.

The crash remained reproducible.

Therefore TgCrypto does not appear to be the cause.

python-socks

I also tested the relevant configuration without python-socks being responsible for the failure.

The crash remained reproducible.

Minimal Kurigram test

I created a minimal Kurigram program that performs a Telegram API operation.

The minimal program did not reproduce the crash.

Therefore I currently do not have a sufficiently small SSCCE that reproduces the issue independently of the application.

The failure appears to require a more complex interaction between:

  • Nuitka-compiled Kurigram code.
  • asyncio.
  • Telegram message parsing.
  • The application's asynchronous workflow.
  • The Kurigram changes introduced after ed4a0ba3.

↩️ Regression

This is a regression with respect to the Kurigram revision used by the application.

The important result is:

ed4a0ba3b34980f2cdc15e4c4d986b57608c958a
    -> Nuitka build works

15df274030a9d11cc76cbadf5a0b1b9e962d83f1
    -> Nuitka build crashes

This result was obtained while keeping the Nuitka/Python environment fixed.

For the primary reproduction:

Python 3.11.7
Nuitka 2.8.10

The regression boundary is different with other Python versions. Python 3.11.7 can run newer Kurigram revisions than Python 3.13.2/3.14.3 before encountering the same class of failure.

This difference makes me suspect that the Kurigram change may expose a Nuitka code-generation/runtime issue rather than simply being an ordinary Python runtime bug.

Additional Context

The original application is:

https://github.com/Gentlesprite/Telegram_Restricted_Media_Downloader/tree/8ddfa62bc638f7d6110e230faa37f3e64a935665

The project works normally when executed with CPython.

The important regression is only observed after compiling the affected asynchronous Telegram workflow with Nuitka.

The first known bad Kurigram commit is:

15df274030a9d11cc76cbadf5a0b1b9e962d83f1

while:

ed4a0ba3b34980f2cdc15e4c4d986b57608c958a

is known to work under the same primary environment.

I would appreciate help determining whether this is a Nuitka code-generation/runtime issue involving the newly introduced asynchronous get_message_split_ranges() / invoke() path, particularly around compiled coroutine/frame handling, reference counting, or interaction with the onefile runtime.

At this point I am intentionally not claiming that 15df2740 is itself a bug in Kurigram; it is simply the first known bad revision from the reproducible bisect.