Skip to content

Commit

Permalink
Fix thread-safety of the module
Browse files Browse the repository at this point in the history
Concurrent access to the `%rfc_grammar` hash has to be lock-protected.
  • Loading branch information
vrurg committed Dec 24, 2023
1 parent ed95cad commit 9df401b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/IETF/RFC_Grammar.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ unit class IETF::RFC_Grammar;
my %rfc_grammar_build = (
'rfc3986' => 'IETF::RFC_Grammar::URI'
);
my $rfc_grammar_lock = Lock.new;
my %rfc_grammar;

# Hack to give hint to ufo/Panda to build in the right order.
Expand All @@ -31,17 +32,19 @@ submethod BUILD(:$!rfc, :$!grammar) {}
method new(Str $rfc, $grammar?) {
my $init_grammar = $grammar;

if (
(! $init_grammar.can('parse')) and
%rfc_grammar_build{$rfc}:exists;
) {
unless %rfc_grammar{$rfc}:exists {
my $module = %rfc_grammar_build{$rfc};
# less disruptive fix to RT126390
unless ($rfc eq 'rfc3986') { require ::($module); }
%rfc_grammar{$rfc} = ::($module);
$rfc_grammar_lock.protect: {
if (
(! $init_grammar.can('parse')) and
%rfc_grammar_build{$rfc}:exists;
) {
unless %rfc_grammar{$rfc}:exists {
my $module = %rfc_grammar_build{$rfc};
# less disruptive fix to RT126390
unless ($rfc eq 'rfc3986') { require ::($module); }
%rfc_grammar{$rfc} = ::($module);
}
$init_grammar = %rfc_grammar{$rfc};
}
$init_grammar = %rfc_grammar{$rfc};
}
if (! $init_grammar.can('parse')) {
die "Need either rfc with known grammar or grammar";
Expand Down

0 comments on commit 9df401b

Please sign in to comment.