GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Possible data race in `_io_IncrementalNewlineDecoder_reset_impl` in `textio.c` · Issue #144777 · python/cpython

Possible data race in _io_IncrementalNewlineDecoder_reset_impl in textio.c #144777

New issue
Copy link
New issue
Copy link
Closed
Closed
Possible data race in _io_IncrementalNewlineDecoder_reset_impl in textio.c#144777
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-IOtopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@Naserume
Naserume
opened on Feb 13, 2026
Issue body actions

Bug report

Bug description:

This code produces TSAN warning on no-gil build, but I'm not sure if this is a real bug since the docs mention TextIOWrapper isn't thread safe.

import codecs
from threading import Thread
from io import IncrementalNewlineDecoder

utf8_decoder = codecs.getincrementaldecoder('utf-8')()
OBJ = IncrementalNewlineDecoder(utf8_decoder, translate=True)

def test1():
    for _ in range(100):
        OBJ.reset()

def main():
    threads = []
    for _ in range(4):
        threads.append(Thread(target=test1))
    for t in threads:
        t.start()
    for t in threads:
        t.join()

if __name__ == "__main__":
    main()

TSAN report:

WARNING: ThreadSanitizer: data race (pid=481349)
  Write of size 1 at 0x7fffb496d230 by thread T4:
    #0 _io_IncrementalNewlineDecoder_reset_impl /cpython/./Modules/_io/textio.c:627:21 (python3.15t+0x5b8b15)
    #1 _io_IncrementalNewlineDecoder_reset /cpython/./Modules/_io/clinic/textio.c.h:492:12 (python3.15t+0x5b8b15)
    #2 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:3943:35 (python3.15t+0x42d408)
    #3 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x422090)
    #4 _PyEval_Vector /cpython/Python/ceval.c:2125:12 (python3.15t+0x422090)
    #5 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x20cc0f)
    #6 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:136:11 (python3.15t+0x2112e6)
    #7 method_vectorcall /cpython/Objects/classobject.c:74:20 (python3.15t+0x2112e6)
    #8 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:136:11 (python3.15t+0x476281)
    #9 context_run /cpython/Python/context.c:727:29 (python3.15t+0x476281)
    #10 _PyCallMethodDescriptorFastWithKeywords_StackRefSteal /cpython/Python/ceval.c:913:11 (python3.15t+0x423f4c)
    #11 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:3852:35 (python3.15t+0x42d1e9)
    #12 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x422090)
    #13 _PyEval_Vector /cpython/Python/ceval.c:2125:12 (python3.15t+0x422090)
    #14 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x20cc0f)
    #15 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:136:11 (python3.15t+0x2112e6)
    #16 method_vectorcall /cpython/Objects/classobject.c:74:20 (python3.15t+0x2112e6)
    #17 _PyVectorcall_Call /cpython/Objects/call.c:273:16 (python3.15t+0x20c89b)
    #18 _PyObject_Call /cpython/Objects/call.c:348:16 (python3.15t+0x20c89b)
    #19 PyObject_Call /cpython/Objects/call.c:373:12 (python3.15t+0x20c905)
    #20 thread_run /cpython/./Modules/_threadmodule.c:387:21 (python3.15t+0x5f5512)
    #21 pythread_wrapper /cpython/Python/thread_pthread.h:234:5 (python3.15t+0x526127)

  Previous write of size 1 at 0x7fffb496d230 by thread T3:
    #0 _io_IncrementalNewlineDecoder_reset_impl /cpython/./Modules/_io/textio.c:627:21 (python3.15t+0x5b8b15)
    #1 _io_IncrementalNewlineDecoder_reset /cpython/./Modules/_io/clinic/textio.c.h:492:12 (python3.15t+0x5b8b15)
    #2 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:3943:35 (python3.15t+0x42d408)
    #3 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x422090)
    #4 _PyEval_Vector /cpython/Python/ceval.c:2125:12 (python3.15t+0x422090)
    #5 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x20cc0f)
    #6 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:136:11 (python3.15t+0x2112e6)
    #7 method_vectorcall /cpython/Objects/classobject.c:74:20 (python3.15t+0x2112e6)
    #8 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:136:11 (python3.15t+0x476281)
    #9 context_run /cpython/Python/context.c:727:29 (python3.15t+0x476281)
    #10 _PyCallMethodDescriptorFastWithKeywords_StackRefSteal /cpython/Python/ceval.c:913:11 (python3.15t+0x423f4c)
    #11 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:3852:35 (python3.15t+0x42d1e9)
    #12 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x422090)
    #13 _PyEval_Vector /cpython/Python/ceval.c:2125:12 (python3.15t+0x422090)
    #14 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x20cc0f)
    #15 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:136:11 (python3.15t+0x2112e6)
    #16 method_vectorcall /cpython/Objects/classobject.c:74:20 (python3.15t+0x2112e6)
    #17 _PyVectorcall_Call /cpython/Objects/call.c:273:16 (python3.15t+0x20c89b)
    #18 _PyObject_Call /cpython/Objects/call.c:348:16 (python3.15t+0x20c89b)
    #19 PyObject_Call /cpython/Objects/call.c:373:12 (python3.15t+0x20c905)
    #20 thread_run /cpython/./Modules/_threadmodule.c:387:21 (python3.15t+0x5f5512)
    #21 pythread_wrapper /cpython/Python/thread_pthread.h:234:5 (python3.15t+0x526127)

SUMMARY: ThreadSanitizer: data race /cpython/./Modules/_io/textio.c:627:21 in _io_IncrementalNewlineDecoder_reset_impl

Version: Python 3.15.0a5+ free-threading build (heads/main:d5f96c86653, Feb 11 2026, 04:50:14) [Clang 18.1.3 (1ubuntu1)]

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-144777: Fix data races in IncrementalNewlineDecoder #144971
  • [3.14] gh-144777: Fix data races in IncrementalNewlineDecoder (gh-144971) #145143

Activity

  1. Naserume
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Feb 13, 2026
  2. StanFromIreland
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-IO
    topic-free-threading
    on Feb 13, 2026
  3. Krishna-web-hub commented on Feb 13, 2026

    @Krishna-web-hub
    Krishna-web-hub
    on Feb 13, 2026
    Contributor
    More actions

    Hello @Naserume , i think this error is due to the free threaded python which causes data race condition and also in the doc it is mentioned that TextIOWrapper is not safe. I think @StanFromIreland can give us some direction on whether to work on it or not.

  4. colesbury
    added 4 commits that reference this issue on Feb 18, 2026

    pythongh-144777: Fix data races in IncrementalNewlineDecoder

    c063bd1

    gh-144777: Fix data races in IncrementalNewlineDecoder (gh-144971)

    8db8fc9

    [3.14] pythongh-144777: Fix data races in IncrementalNewlineDecoder (p…

    89cacd6

    [3.14] gh-144777: Fix data races in IncrementalNewlineDecoder (gh-144971

    bbb0f2d
  5. colesbury commented on Feb 23, 2026

    @colesbury
    colesbury
    on Feb 23, 2026
    Contributor
    More actions

    Thanks for the bug report!

  6. colesbury
    closed this as completedon Feb 23, 2026
  7. brijkapadia
    added a commit that references this issue on Feb 28, 2026

    pythongh-144777: Fix data races in IncrementalNewlineDecoder (pythong…

    fb04208
  8. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-144777: Fix data races in IncrementalNewlineDecoder (pythong…

    4812e69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-IOtopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.