oracle / oracle/graalpython

Python context isolation broken?

Open
#20 6 comments 0 reactions 1 assignee View on GitHub

@lukasstadler is already working on this.

Since Oct 2, 2018.

Dominant language
Python
Stars
1.6k
Forks
155
Avg merge
9h 42m
Merged PRs (30d)
36

Description

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Source;

/** Created by revin on Oct.1,2018. */
public class BugReport{
    public void trace(Object x){System.out.println(x);}
    public static void main(String...args)throws Exception{
        Engine engine=Engine.create();
        Context c0=Context.newBuilder().allowIO(true).engine(engine).build();
        Context c1=Context.newBuilder().allowIO(true).engine(engine).build();

        Source source=Source.newBuilder("python",
                "import polyglot\n"+
                "try:bug.trace(\"SHOULD NOT SEE THIS\")\nexcept:pass\n"+
                "bug=polyglot.import_value(\"bug\")\n"
                ,"bugReport.py").build();

        BugReport bug=new BugReport();
        long nano0=System.nanoTime();c0.getPolyglotBindings().putMember("bug",bug);c0.eval(source);
        long nano1=System.nanoTime();c1.getPolyglotBindings().putMember("bug",bug);c1.eval(source);
        long nano2=System.nanoTime();System.out.println((nano1-nano0)/1000_000+" ms without init, "+(nano2-nano1)/1000_000+" ms after init");
    }
}

image

expected output: none
actual output: "SHOULD NOT SEE THIS"

as you can see from the simplified code above:
it creates two separate contexts, run the same code in each one of them
but it seems somehow the global variable bug leaked from the first context into the second one

am I misunderstood something here? how can I achieve performant context isolation?
context initialization(even if they use the same engine instance underneath) seems very heavy

Contributor guide

Open the contributing guide

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.