Skip to content

Race condition in vparser.parser.parse during multi-processing due to static preprocess_output filename #139

@Hinataee

Description

@Hinataee

There is a potential race condition in the vparser.parser.parse function and VerilogCodeParser class when multiple instances are running concurrently in the same working directory (e.g., using multiprocessing).

The default value for preprocess_output is hardcoded as 'preprocess.output':

# pyverilog/vparser/parser.py

def parse(filelist, ... preprocess_output='preprocess.output'):
    codeparser = VerilogCodeParser(..., preprocess_output=preprocess_output)
    # ...

class VerilogCodeParser(object):
    def __init__(self, filelist, preprocess_output='preprocess.output', ...):
        # ...

Impact

When multiple processes call parse() simultaneously:

  1. One process may overwrite the preprocess.output file while another is reading it.
  2. One process may delete the file (via os.remove) while another still needs it.
  3. This leads to IOError, FileNotFoundError, or corrupted AST results.

Suggested Fix

Consider using a unique temporary filename by default using the tempfile module, or clearly document that users must provide a unique preprocess_output path when running in parallel.

import tempfile
# Use a temporary file instead of a fixed string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions