microsoft / microsoft/Power-Fx

NullRef in IExternalStringResources.TryGetErrorResource

Open
#2,528 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.4k
Forks
358
Avg merge
10h 34m
Merged PRs (30d)
3

Description

#2514 removed a lock (to avoid a horrible performance problem from contention) - but this means now we're reading a (non-concurrent) dictionary outside of the lock. This is manifesting as race condition / non-deterministic null-ref exceptions here:

https://github.com/microsoft/Power-Fx/blob/bcc750b19172ce712d75e50019f50c64d0c5d784/src/libraries/Microsoft.PowerFx.Core/Localization/StringResources.cs#L234

TryGet succeeds and hands back a null localizedErrorResources - likely due to a race (accessing a dictionary from multiple threads)

Naive fix is to protect this with a reader-writer lock.

  Message: 
System.NullReferenceException : Object reference not set to an instance of an object.

  Stack Trace: 
Dictionary`2.FindEntry(TKey key)
Dictionary`2.TryGetValue(TKey key, TValue& value)
IExternalStringResources.TryGetErrorResource(ErrorResourceKey resourceKey, ErrorResource& resourceValue, String locale)
ErrorUtils.GetLocalizedErrorContent(ErrorResourceKey errKey, CultureInfo locale, ErrorResource& errorResource)
BaseError.ctor(IDocumentError innerError, Exception internalException, DocumentErrorKind kind, DocumentErrorSeverity severity, ErrorResourceKey errKey, Span textSpan, IEnumerable`1 sinkTypeErrors, Object[] args)
BaseError.ctor(IDocumentError innerError, Exception internalException, DocumentErrorKind kind, DocumentErrorSeverity severity, ErrorResourceKey errKey, Object[] args)
TexlError.ctor(TexlNode node, DocumentErrorSeverity severity, ErrorResourceKey errKey, Object[] args)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/libraries/Microsoft.PowerFx.Core/Localization/StringResources.cs at line 234 and review the lock removal referenced in #2514. Investigate concurrent access through IExternalStringResources.TryGetErrorResource and verify that concurrent calls no longer produce a null localizedErrorResources or NullReferenceException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
localization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.