Skip to content

Crash with glib #1471

Closed
Closed
@ccremer

Description

@ccremer

Magick.NET version

"Magick.NET-Q8-x64" Version="13.4.0"

Environment (Operating system, version and so on)

Linux (Mint 21.2 (Ubuntu-Based))

Description

When running in multi-threaded context (e.g. ASPNET Core), using MagickNET is hard crashing when another process is depending on glib (I think).

As described in https://rachelbythebay.com/w/2017/01/30/env/ and in glib manual:

Modifications of environment variables are not allowed in multi-threaded programs.

The app crashes particularly when reaching Environment.SetEnv("MAGICK_TEMPORARY_PATH", TemporaryDirectory);.

Here's a log excerpt:

info: WebApplication1.MagicNetInitialization[0]
      Initializing MagickNet /home/chris/source/scratchpad/TestProject1/WebApplication1
**
GLib-GObject:ERROR:../gobject/gvaluetypes.c:455:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)
Bail out! GLib-GObject:ERROR:../gobject/gvaluetypes.c:455:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)

Steps to Reproduce

https://gist.github.com/ccremer/ced17eb8c177003bd81ba727c2f5bda7

Included in the gist is IronPDF, a library to render PDFs. Without this library, MagickNET doesn't crash, but since IronPDF depends on Chrome, and Chrome itself on glib as well, the program will crash when you start it up.

However, if you swap the order of the boot from

builder.Services.AddHostedService<IronPdfInitialization>();
builder.Services.AddHostedService<MagicNetInitialization>();

to

builder.Services.AddHostedService<MagicNetInitialization>();
builder.Services.AddHostedService<IronPdfInitialization>();

then it works.

Still, calling setenv is forbidden in this context.
Is it possible we can skip this and setup the required environment variables by ourselves, without MagickNET trying to do it again?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions