Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent NullReferenceExceptions #66

Open
Seltzer opened this issue Jun 24, 2018 · 3 comments
Open

Intermittent NullReferenceExceptions #66

Seltzer opened this issue Jun 24, 2018 · 3 comments

Comments

@Seltzer
Copy link

Seltzer commented Jun 24, 2018

Hi!

I'm using libsass-net to compile a top level SCSS file which imports about 20 ancestor files (code attached). I'm seeing intermittent NullReferenceExceptions maybe once every 5-10 compilations and the point of failure varies (i.e. the import after which it dies). Here's the stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
at LibSass.Compiler.SassExterns64.sass_compile_data_context(SassSafeDataContextHandle data_context)
at LibSass.Compiler.Context.SassSafeDataContextHandle.CompileInternalContext()
at LibSass.Compiler.Context.SassSafeContextHandle.CompileContext()

Given this, I assume it's something going wrong inside libsass itself. I can reliably reproduce this by periodically making requests to our endpoint which compiles that top level file. I would guess that it's unrelated to concurrency as I'm waiting a few seconds in between. However, it's quite possible that libsass is being dodgy and sharing some state between compilations.

I attempted to debug it and track it down by building libsass 3.3.6 from source with logging statements attached. Didn't have much luck though. This is possibly the same issue as #60.

I haven't lodged a bug report with libsass as I'm unsure whether it's still a bug in their latest version. How much effort do you think would be required to bring libsass-net up to date so that it works with 3.5.4? I might end up giving it a shot.

var compilerOptions = new SassOptions
{
Data = topLevelScss,
EmbedSourceMap = true,
OutputStyle = SassOutputStyle.Expanded,
Importers = new[] { BuildImportResolver(scssResources) },
};

var sassCompiler = new SassCompiler(compilerOptions);
var compilationResult = sassCompiler.Compile();

@Seltzer
Copy link
Author

Seltzer commented Jul 10, 2018

Hi @darrenkopp

I'm just wondering, how much effort do you think would be required if I were to attempt to make libsass-net work with the latest version of libsass? Is there anything I should watch out for in particular?

Cheers

@darrenkopp
Copy link
Collaborator

I don't think there's anything to watch out for. The biggest hurdle is likely going to be getting it to compile on windows, then it's a simple matter of mapping P/Invoke commands for anything that's changed (if anything)

@SorenHK
Copy link

SorenHK commented Sep 13, 2018

I am facing the samme issue with the exact same exception as @Seltzer (NullReferenceException). I've figured out that the actual exception is:

'CallbackOnCollectedDelegate' : 'A callback was made on a garbage collected delegate of type 'LibSass.NET!LibSass.Compiler.SassImporterDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.'

I have, however, managed to "handle" it by simply retrying the compilation when this exception is thrown. In my testing the exception was thrown, on average, every 300 compilations. Retrying with up to a few attempts seems reasonable until a permanent fix is implemented. I have yet to see two consecutive failed compilations in a row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants