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

interp: fix data races #839

Merged
merged 1 commit into from
Sep 9, 2020
Merged

interp: fix data races #839

merged 1 commit into from
Sep 9, 2020

Conversation

mpl
Copy link
Collaborator

@mpl mpl commented Sep 8, 2020

This change fixes two distinct data races:

  1. some global vars of type *itype of the interp package are actually
    mutated during the lifecycle of an Interpreter. Even worse: if more than
    one Interpreter instance are created and used at a given time, they are
    actually racing each other for these global vars.
    Therefore, this change replaces these global vars with generator
    functions that create the needed type on the fly.

  2. the symbols given as argument of Interpreter.Use were directly copied
    as reference (since they're maps) when mapped inside an Interpreter
    instance. Since the usual case is to give the symbols from the stdlib
    package, it means when the interpreter mutates its own symbols in
    fixStdio, it would actually mutate the corresponding global vars of the
    stdlib package. Again, this is at least racy as soon as several
    instances of an Intepreter are concurrently running.
    This change fixes the race by making sure Interpreter.Use actually
    copies the symbol values instead of copying the references.

This change fixes two distinct data races:

1) some global vars of type *itype of the interp package are actually
mutated during the lifecycle of an Interpreter. Even worse: if more than
one Interpreter instance are created and used at a given time, they are
actually racing each other for these global vars.
Therefore, this change replaces these global vars with generator
functions that create the needed type on the fly.

2) the symbols given as argument of Interpreter.Use were directly copied
as reference (since they're maps) when mapped inside an Interpreter
instance. Since the usual case is to give the symbols from the stdlib
package, it means when the interpreter mutates its own symbols in
fixStdio, it would actually mutate the corresponding global vars of the
stdlib package. Again, this is at least racy as soon as several
instances of an Intepreter are concurrently running.
This change fixes the race by making sure Interpreter.Use actually
copies the symbol values instead of copying the references.
Copy link
Member

@mvertes mvertes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mvertes mvertes added area/core area/test bug Something isn't working labels Sep 9, 2020
@mvertes mvertes added this to the v0.8.x milestone Sep 9, 2020
@mvertes mvertes merged commit 04770a4 into traefik:master Sep 9, 2020
mvertes added a commit that referenced this pull request Sep 9, 2020
@mpl mpl deleted the datarace branch September 9, 2020 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/test bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants