Code Monkey home page Code Monkey logo

dmoj / judge-server Goto Github PK

View Code? Open in Web Editor NEW
880.0 29.0 249.0 7.03 MB

Judging backend server for the DMOJ online judge.

Home Page: https://dmoj.ca

License: GNU Affero General Public License v3.0

Python 51.81% C 1.46% C++ 42.49% Dockerfile 0.21% Makefile 0.06% Shell 0.13% Java 0.99% Pascal 0.03% Go 0.04% C# 0.08% Assembly 0.04% Roff 0.01% Cython 2.11% Rust 0.05% Brainfuck 0.51%
online-judge sandbox competitive-programming computer-science linux freebsd contest-platform python

judge-server's People

Contributors

alexwaeseperlman avatar aurpine avatar balint-r avatar carson-tang avatar cuom1999 avatar dessertion avatar dmoj-build avatar ehhthing avatar fataleagle avatar fengb avatar github-actions[bot] avatar hieplpvip avatar injust avatar int-y1 avatar kipply avatar kiritofeng avatar mikejgray avatar mmun avatar ninjaclasher avatar phoenix1369 avatar puffyshoggoth avatar pxpeterxu avatar quantum5 avatar rigwild avatar riolku avatar walle256 avatar wesley-a-leung avatar xiaowuc1 avatar xyene avatar yukarinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

judge-server's Issues

Signature grading for Java

Should be possible to bind a C grader to a JNI interface and provide callbacks. Will require a lot of machine-generated code.

Executable size limit

We can set RLIMIT_FSIZE to limit the maximum file size a compiler can possibly create. However, setting this limit in the judge process is not a trivial matter. A clean solution requires a script which sets the limit and execves the compiler, which would require a utility function to spawn compilers as this only works on *nix. The helper might also need to catch SIGXFSZ exit and raise compile error as appropriate.

Needless to say, this has no priority.

Apparently dependency on C++11 being available

Traceback (most recent call last):
  File "/var/lib/openshift/532715544382ec40ff00017a/app-root/data/judge/judge.py", line 269, in _begin_grading
    short_circuit=short_circuit, source_code=original_source, interactive=('grader' in init_data)):
  File "/var/lib/openshift/532715544382ec40ff00017a/app-root/data/judge/judge.py", line 566, in run
    topen = self._resolve_open_call(init_data, problem_id, forward_test_cases)
  File "/var/lib/openshift/532715544382ec40ff00017a/app-root/data/judge/judge.py", line 356, in _resolve_open_call
    generator_launcher = clazz.Executor('%s-generator' % problem_id, generator_source).launch_unsafe
  File "/var/lib/openshift/532715544382ec40ff00017a/app-root/data/judge/executors/GCCExecutor.py", line 57, in __init__
    raise CompileError(compile_error)
CompileError: cc1plus: error: unrecognized command line option "-std=c++11"

LANG=C for compilers

Would prevent awesome havoc when the system language is set to something like zh_CN. GCC would be more than happy to give translated messages, puzzling everyone.

Note: Herculaneum uses Unicode smart quotes in error messages exactly for this reason.

Obtuse docs lead to magical status codes

The Java submission:

public class Clazz {
    public static void main(String[] argv) {
    }

    static {
        String x = "x";
        for(int i = 0; i < 1000000; i++) x += x;
    }
}

Will not produce an MLE status code as expected, but rather an IR. The offending line? https://github.com/DMOJ/judge/blob/master/java_executor/src/ca/dmoj/java/SubmissionThread.java#L27

But why? Clearly the OutOfMemoryError is handled. The reason is quite illegit. Let's take a look at the docs for java.lang.reflect.Method#invoke (emphasis mine, cruft removed).

If the underlying method is static, the class that declared the method is initialized if it has not already been initialized.

Throws:

  • InvocationTargetException - if the underlying method throws an exception.
  • ExceptionInInitializerError - if the initialization provoked by this method fails.

Now, at this time, the class that declared the method is not initialized. So we're not given an InvocationTargetException when the static block runs out of heap space. Easy though, right? Just wrap the invocation to catch ExceptionInInitializerError, and check if the cause is an OutOfMemoryError. No.

In my experience with the Java language and Java documentation, the terms "Exception" and "Error" are used quite interchangeably. InvocationTargetException states that it will be thrown if "if the underlying method throws an exception", but this is not true. It will be thrown if the underlying method throws any Throwable - indeed, the entire Java executor relies on this. It's therefore only logical to assume that ExceptionInInitializerError would act the same. It doesn't.

Unlike what you might expect, it only gets thrown if the initialization throws an Exception. Not a Throwable, as you might believe - an Exception. Hence, "correct" code would wrap the invocation call with a try/catch block for OutOfMemoryError, which, by virtue of being an Error, will not be wrapped in ExceptionInInitializerError.

Thanks, Java.

This rant issue took less time to write than this bug took to identify.

IE when submission ignores stdin data.

When operating on the child's stdin on Windows, and the child ignores all the input, IOError: [Errno 22] Invalid argument is caused when the buffer is flushed. This happens on write or close, and causes exceptions.

Sample tracebacks:

Traceback (most recent call last):
  File "C:\Users\Quantum\Desktop\judge\judge.py", line 281, in _begin_grading
    interactive=('grader' in init_data)):
  File "C:\Users\Quantum\Desktop\judge\judge.py", line 664, in run
    result.proc_output, error = communicate(input_data, outlimit=25165824, errlimit=1048576)
  File "C:\Users\Quantum\Desktop\judge\communicate.py", line 53, in safe_communicate
    proc.stdin.write(input)
IOError: [Errno 22] Invalid argument
Traceback (most recent call last):
  File "C:\Users\Quantum\Desktop\judge\judge.py", line 281, in _begin_grading
    interactive=('grader' in init_data)):
  File "C:\Users\Quantum\Desktop\judge\judge.py", line 664, in run
    result.proc_output, error = communicate(input_data, outlimit=25165824, errlimit=1048576)
  File "C:\Users\Quantum\Desktop\judge\communicate.py", line 63, in safe_communicate
    proc.stdin.close()
IOError: [Errno 22] Invalid argument

Local grading server UI

Would by highly useful for problemsetters without installing the DMOJ Django site. Could be written as a lightweight Java applet that implements a minimal grading UI.

It would reduce the amount of effort that needs to go into organizing contests, since data would not have to be uploaded for every try. Would also be useful for allowing this judge to be used as a standalone program for private training (there are more stars on this repo than the site repo, which might be indicative that some potential users are interested in private graders).

Clang

According to some StackOverflow post, Clang is recommended for students due to "extremely clear diagnostics are definitely easier for beginners to interpret". The idea is rather popular to the point that GCC tries to debunk it as a myth.

It might be worth to add clang as an alternative C/C++ frontend.

`cptbox` improvements.

  1. Add option to only track process creation and exiting PTRACE_O_TRACE*.
  2. A SecurePopen-compatible class to log only only these events. Useful for example to track languages with builtin sandbox without performance penalty.
  3. Port cptbox to more platforms, most notably linux x32 to use 64-bit powers with only 32-bit pointers.

Class-based GCC executor

A class-based approach is fully modifiable by subclasses instead of making the make_executor function take more and more arguments.

Interactive grader should take strings

Well you see, normal grader takes string to safe_communicate, checkers also take strings, but these interactive graders, take umm, cStringIO.StringIO???

Generator cache

Some generators take prohibitively long times to generate testdata, and in a contest scenario it would be beneficial to have a cache of generated data so that subsequent submissions run faster. The cache would likely expire after a few minutes, to free resources.

Judge API

Importing classes from judge.py for use in interactive graders/custom checkers is nasty and ultimately depends highly on the current judge version, forcing any future changes to the internals to be signature-compatible.

An API could easily resolve this.

Uncleaned wbox accounts

When wbox crashes, its generated accounts are never cleaned. They should be cleaned the next time the judge boots.

C:\Users\Tudor>net user

User accounts for \\BERLIN

-------------------------------------------------------------------------------
Administrator            Guest                    Tudor
-----------              wbox0000000000c6afaf     wbox0000000001871be0
wbox00000000018a93b8     wbox000000000191d021     wbox0000000001aa8ccc
wbox0000000001b196a0     wbox000000000ace72e2     wbox000000000b23e734
wbox000000000b296475     wbox000000000b324dc7     wbox000000000ba9c9f5
wbox000000000bb804e8     wbox000000000bbb3434
The command completed successfully.

Errno 10013 after abnormal termination on Windows

socket.error: [Errno 10013] An attempt was made to access a socket in a way for idden by its access permissions

After exiting from the issue documented in #5 , Windows judges are not able to connect again.

Option to run system checks without sandbox

For DMOJ/hephaestus to work, we have to have the option of running all the executors without the sandbox. Ideally this would mean migrating most duplicate executor features into ResourceProxy and renamed BaseExecutor. This BaseExecutor would then be able to expose the basic features as seen fit.

System.exit for Java

Since the user submission runs in the same process as the judge executor calls to System.exit are blocked such that the user does not exit the grading JVM.

Should be trivial to handle the exit permission request and kill the submission thread instead of throwing an AccessControlException.

Abysmal error handling

The judge servers were written to "chug along", but this has a terrible effect on error messages.

The following traceback is generated when a user misconfigures a problem:

Traceback (most recent call last):

  File "/code/site/judge/bridge/judgehandler.py", line 199, in on_bad_problem
    raise ValueError('\n\n' + packet['message'])

ValueError:

Traceback (most recent call last):
  File "/judge/judge/judge.py", line 185, in _begin_grading
    with open(os.path.join(get_problem_root(problem_id), 'init.json'), 'r') as init_file:
  File "/usr/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

Intuitive, right? Very helpful to those who are not familiar with the judge's source code.

"\w+\.exe has stopped working" on OLE on Windows

OLE

Using checker standard
judge-connect.dmoj.ca:15000 => {
    "name": "grading-begin",
    "submission-id": 52896
}
OLE: stdout

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Multiple judge support

On powerful computers it may be beneficial to support the running more than one judge without going through the pain of having to copy the judge directory. Simply pass a path to a judge json model as an optional commandline parameter, and default to /data/judge/judge.json for compatibility with judges that are already set up.

Unbuffered I/O for interactive problems

A certain online judge doesn't require flushing for interactive problems. A wild guess scientific analysis suggests that they present pty devices for stdin and stdout. This can be arranged on *nix through the use of the pty module's openpty() in place of os.pipe().

Checkers take longer than submission

For linked list, the checker takes longer than the submission itself to check the data.

Some profile data:

name                                  ncall  tsub      ttot      tavg
..judge/checkers/standard.py:1 check  25     20.60029  39.94269  1.597708

The submission itself takes 7.69s. This is clearly not acceptable. I suggest we start porting checkers to C.

Fully class-based executor system

The current executor system does not take advantage of inheritance and modularization. This should be changed so that small changes doesn't have to cause all executors to be changed, e.g. #47, #34.

Haskell Optimization

I don't think Haskell "A Plus B" program should take 2.5 seconds...

Also, according to this documentation, -O produced reasonable code at a reasonable speed, while "At the moment, -O2 is unlikely to produce better code than -O."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.