Skip to content

On Linux, attaching debugger to a running process causes the process to segfault #882

Closed
@mosbasik

Description

@mosbasik

Issue Type: Bug

Behaviour

Expected vs. Actual

I ran a simple python script that alternates between print() and sleep() forever, then I tried to attach the debugger to it. I expected to gain control of the process with the debugger. But actually, the process segfaulted.

Steps to reproduce:

I'm using Python 3.9 in a virtualenv on Arch Linux.

I disable all of my extensions from the Extensions tab using "Disable all installed extensions", and then re-enable only the Python extension to get the debugger.

I run the following Python script:

test.py:

import itertools
from time import sleep

def main():
    for i in itertools.count():
        print( f'Hello! ({i})' )
        sleep( 2 )

if __name__ == '__main__':
    main()

And then I try to attach to it using the following debugger setup:

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name":"Python: Attach using Process Id",
            "type":"python",
            "request":"attach",
            "processId":"${command:pickProcess}",
            "logToFile": true,
            "console": "internalConsole",
            "env": {
                "PTVSD_DEBUG": "1",
            }
        },
    ]
}

Here's what the ouput of the script looks like:

$ python -u test.py
Hello! (0)
Hello! (1)
Hello! (2)
Hello! (3)
Hello! (4)   // once this is is printed, I attempt to attach
The threading module was not imported by user code in the main thread. The debugger will attempt to work around https://bugs.python.org/issue37416.
[1]    469716 segmentation fault (core dumped)  python -u test.py

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.12
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): VirtualEnvWrapper
  • Value of the python.languageServer setting: Pylance
User Settings


defaultLS: {"defaultLSType":"Pylance"}

downloadLanguageServer: true

envFile: "<placeholder>"

venvPath: "<placeholder>"

venvFolders: "<placeholder>"

condaPath: "<placeholder>"

pipenvPath: "<placeholder>"

poetryPath: "<placeholder>"

languageServer: "Pylance"

linting
• enabled: false
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: false
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: true
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"

sortImports
• args: "<placeholder>"
• path: "<placeholder>"

formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "none"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"

testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: false
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: true

terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"

experiments
• enabled: true
• optInto: []
• optOutFrom: []

insidersChannel: "off"

tensorBoard
• logDirectory: "<placeholder>"

Extension version: 2022.2.1924087327
VS Code version: Code - OSS 1.65.2 (c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1, 2022-03-10T19:23:12.185Z)
OS version: Linux x64 5.16.16-arch1-1
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz (4 x 3389)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 1, 2, 2
Memory (System) 15.53GB (1.03GB free)
Process Argv --unity-launch
Screen Reader no
VM 0%
DESKTOP_SESSION undefined
XDG_CURRENT_DESKTOP undefined
XDG_SESSION_DESKTOP undefined
XDG_SESSION_TYPE undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions