conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.3k stars 985 forks source link

[bug] Conan graph crash on big tree #17245

Closed Marc-Pierre-Barbier closed 3 weeks ago

Marc-Pierre-Barbier commented 3 weeks ago

Describe the bug

This issue is a copy of the one created on colorama's github: https://github.com/tartley/colorama/issues/396

I was using conan2's command conan graph info . --format=html > output.html which generate a html report to a file

~the problem is that conan use colorama to print and the massive input led to a recursion limit~

so inside ansitowin32.py i added this piece of code at the begning of write

 def write(self, text):
        global last_write
        last_write+=1
        f = open("/tmp/conankaboum" + str(last_write), "a")
        f.write(text)
        f.close()
        ....

which wrote a 383KB file called "conankaboum206" and 205 other identical files i will be creating a similar report on conan's side. conankaboum206.txt

here is the looping part of the stacktrace

  File "/usr/local/lib/python3.11/site-packages/colorama/ansitowin32.py", line 176, in write
    self.write_and_convert(text)
  File "/usr/local/lib/python3.11/site-packages/colorama/ansitowin32.py", line 204, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "/usr/local/lib/python3.11/site-packages/colorama/ansitowin32.py", line 209, in write_plain_text
    self.wrapped.write(text[start:end])
  File "/usr/local/lib/python3.11/site-packages/colorama/ansitowin32.py", line 46, in write
    self.__convertor.write(text)
  File "/usr/local/lib/python3.11/site-packages/colorama/ansitowin32.py", line 176, in write
    self.write_and_convert(text)
  File "/usr/local/lib/python3.11/site-packages/colorama/ansitowin32.py", line 198, in write_and_convert
    text = self.convert_osc(text)

How to reproduce it

Create a very big tree.

no clue if it's the only requirement but on the colorama page i put the html input which caused the crash. and each iteration was identical so this bug is definitely a colorama bug.

it can be replicated by taking the file 'conankaboum206.txt' and using it in colorama's write

Marc-Pierre-Barbier commented 3 weeks ago

for other people experiencing this issue here is a workaround:

redirecting stderr to a file will disable the use of colorama preventing the crash.

memsharded commented 3 weeks ago

Thanks for your report @Marc-Pierre-Barbier

For reference the code that is printing a very large string is:


def cli_out_write(data, fg=None, bg=None, endline="\n", indentation=0):
    """
    Output to be used by formatters to dump information to stdout
    """

    fg_ = fg or ''
    bg_ = bg or ''
    if (fg or bg) and _color_enabled(sys.stdout):
        data = f"{' ' * indentation}{fg_}{bg_}{data}{Style.RESET_ALL}{endline}"
    else:
        data = f"{' ' * indentation}{data}{endline}"

    sys.stdout.write(data)

I don't know if there is anything else we can do from Conan side, it doesn't seem so.

Besides the workaround of redirecting the stderr, you can also explicitly disable colorama by defining env-var NO_COLOR, so you can still read the stderr on screen as usual.

memsharded commented 3 weeks ago

I am marking this ticket as "invalid", meaning that this isn't really a Conan bug, and there is nothing that we can do from our side at the moment, it seems this can only be fixed from the colorama side.

Marc-Pierre-Barbier commented 3 weeks ago

I am marking this ticket as "invalid", meaning that this isn't really a Conan bug, and there is nothing that we can do from our side at the moment, it seems this can only be fixed from the colorama side.

Colorama doesn't seem active anymore, last commit date from 1 year ago.

What could be done is to find a way to make the conan graph go directly to sys.stdout without going through colorama.

memsharded commented 3 weeks ago

Colorama doesn't seem active anymore, last commit date from 1 year ago.

That is quite unfortunate, I knew it was not very active, but not that it was that stale.

What could be done is to find a way to make the conan graph go directly to sys.stdout without going through colorama.

That is the problem, you see the Conan code above is doing sys.stdout.write(data). Conan it is already going directly to sys.stdout, but colorama intercepts it. So I am not sure how this could be solved without a big (and risky) hack. I am starting to have a look to Rich alternative, but this isn't a small change in the best case it will take time.

I wonder if it only fails for the --format=html or does it fail for --format=dot too? and --format=json?

memsharded commented 3 weeks ago

Just checked about colorama.deinit() and colorama.reinit() which I think we can leverage to workaround this at the moment, proposing PR https://github.com/conan-io/conan/pull/17259

memsharded commented 3 weeks ago

https://github.com/conan-io/conan/pull/17259 has been merged, closing this ticket. It will be in next Conan 2.10