ivan-m / graphviz

Haskell bindings to the Graphviz toolkit
Other
64 stars 24 forks source link

Crash possibly caused by Haskell bindings to Graphviz #13

Closed stefjoosten closed 6 years ago

stefjoosten commented 8 years ago

Hi Ivan,

Let me first compliment you with your work on Graphviz for Haskell. I am using it in the Ampersand project (if you are curious, check out the Ampersand Project on Github or drop me a mail.) Your work has made my life easier and I'm grateful for that.

The reason to make an issue in your project is a problem I have run into. The symptoms are this. When I compile a particular script (using the Ampersand compiler), here is what I see on the command prompt:

D:\git\ampersand-models\Blik>Ampersand.exe -fl tryArch.adl --verbose --language=
NL
Reading file tryArch.adl
Processing Architectuur
Generating DotOutput using Sfdp.
<some lines left out by SJ for brevity>
.\RulesInPatternUserStories.gv written.
Generating Png using Sfdp.
.\RulesInPatternUserStories.png written.
Generating Svg using Sfdp.
.\RulesInPatternUserStories.svg written.
Generating Eps using Sfdp.
.\RulesInPatternUserStories.eps written.
.\RulesInPatternUserStories.pdf written.
Generating DotOutput using Sfdp.
.\RulesInPatternArchiMetaModel.gv written.
Generating Png using Sfdp.
Ampersand.exe: Error running utility program: Error messages from sfdp:

D:\git\ampersand-models\Blik>

What is going on?

The Ampersand compiler calls sfdp to make diagrams. For substantial files it easily makes dozens of diagrams. This has been happening for years without failure. Until yesterday. As you can see on the last line of the output, sfdp causes the process to stop. Without the crash, Ampersand would have produced a few more diagrams.

Chasing symptoms

To isolate the problem, I took the file that causes the crash and ran it through sfdp by hand. Here's what happened.

D:\git\ampersand-models\Blik>Sfdp RulesInPatternArchiMetaModel.gv -Tpng -orFile.png

D:\git\ampersand-models\Blik>

To my astonishment, sfdp processed this file without crashing. The chrash occurs only if sfdp is called from inside the Ampersand compiler, but not when it runs stand-alone. For this reason, we suspect the Haskell interface to graphviz. That's where I decided to report this issue to you.

My brother, @hanjoosten, has spent the rest of yesterday trying to diagnose this bug. Without much luck, however. Yet, he managed to find a workaround. That might also shed some light on this issue. It is the sheer size of the graph that makes Ampersand crash. The file that fails is just a little bit too large. By stripping a handful of elements from the Ampersand-script (it doesn't really matter which), the graph becomes smaller and runs without a problem through the Ampersand compiler.

This is where we are stuck. We find ourselves unable to making a diagnosis, let alone find the fix. Could it be possible that the GraphViz interface imposes limitations to the size that can explain what happens? I'm looking forward to your reaction

Thanks in advance for all efforts you might spend to help us out. Yours,

Stef Joosten

To reproduce this bug

Might you want to reproduce this bug, you need to install Ampersand using the installation instruction from the Ampersand documentation. You will find the Ampersand compiler in Github-repository AmpersandTarski/ampersand. The crash first showed up in version AmpersandTarski/ampersand@35600fab8bdf80400aadcd02266d3c09e56a4447, but I expect it to occur in many more versions as well. You will find the Ampersand-script in a file called tryArch.adl. It also resides . in AmpersandTarski/ampersand-models@d1cc0e6ea123e7877672744ee6784fb048729c7d. Only this specific version of tryArch.adl will exhibit the chrash. All previous versions of tryArch.adl ran without crashing. To see the crash, run (from your command prompt)

Ampersand -fl tryArch.adl --verbose
ivan-m commented 8 years ago

I'll have a look at this when I get home tonight (feel free to ping me if I don't respond in another day or so in case I've forgotten).

I haven't dealt much with sfpd, but my suspicion is that this is due to how we end up calling the tools, which uses a temporary file to write the graph into, then call the tool on that (it used to use a pipe but it would chew up RAM like there was no tomorrow). This is where size might become an issue: either the ByteString that is being written out becomes too large, or the temporary file is too large for the system (especially if your $TMPDIR is on a network disk or something for some reason. If the program is indeed crashing, then the resultant temporary files might indeed still be present so you could investigate whether they appear to be correct.

There are a few things that might help to debug this further:

  1. Try using dot rather than sfd to see if it's tool-specific.
  2. Use Data.GraphViz.Commands.IO.runCommand directly to try and do more debugging (e.g. call a script to dump the input file elsewhere).
ivan-m commented 8 years ago

OK, I'm unable to actually look at this tonight.

If nothing else, can you please save the actual Haskell Dot graph representation and either paste or attach it here?

stefjoosten commented 8 years ago

Do you mean the .gv-file? I have attached it after wrapping it in .zip, because github won't have it any other way. Click here for downloading it?

stefjoosten commented 8 years ago

Maybe @hanjoosten wants to comment as well...

ivan-m commented 8 years ago

No, I meant if it was possible to do show on the resulting DotGraph and save that to file.

hanjoosten commented 8 years ago

Hi Ivan, please find requested output.
RulesInPatternArchiMetaModel.txt

ivan-m commented 7 years ago

So, I finally remembered about this issue and try to debug the problem... only to find that I don't have a working install of sfdp as I don't have a triangulation library that Graphviz is built against :s

Can you please try and see if this is an issue with any other GraphvizCommand (e.g. Dot) (I am able to produce png output that way, which makes me think it isn't the library per-se; it's either that sfdp requires extra interaction or else something more local/specific to how you're running it)?

ivan-m commented 7 years ago

OK, I just rebuilt Graphviz... and I am able to produce output using this graph and sfdp (load it into ghci, then run runGraphvizCommand Sfdp testGraph Png "sfpd.png").

So there must be something else going on here. sfpd

stefjoosten commented 7 years ago

@hanjoosten, I have just established that the identical behaviour still exists in Ampersand-v3.7.1 [meatgrinder:aed33e5 of 25-Oct-16]. So I think on our side, the situation is still the same.

hanjoosten commented 7 years ago

Maybe because we are on a Windows machine . did you rebuild for a Linux machine?

ivan-m commented 7 years ago

This was on a Mac.

Are you able to test this with a different DotCommand value (e.g. Dot) just to check if it's to do with sfpd or not?

hanjoosten commented 7 years ago

Yes, I could probably do that thuis weekend

ivan-m commented 6 years ago

It's been a year without updates; I'm going to close this until/unless you are able to provide more details.

hanjoosten commented 6 years ago

Ah, you'r right. Sorry I didn't follow up. We have a workaround, so this issue dropped from our attention. If we bump into it again, it will be possible to provide more details. If that happens, we could reopen this issue. Thanks for your effort!