<commit_before>package scalive;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.net.ServerSocket;
import java.net.Socket;

public class Agent {
    /**
     * @param agentArgs <jarpath> <server port> [class loader id]
     *
     * jarpath is the absolute path this directory:
     *
     * {{{
     * jarpath/
     *   scalive-agent.jar
     *   scalive-client.jar
     *   scalive-repl.jar
     *
     *   2.10.3/
     *     scala-library.jar
     *     scala-compiler.jar
     *     scala-reflect.jar
     *
     *   [Other Scala versions]
     * }}}
     */
    public static void agentmain(String agentArgs, Instrumentation inst) throws IOException {
        final String[] args    = agentArgs.split(" ");
        final String   jarpath = args[0];
        final int      port    = Integer.parseInt(args[1]);
        final String   clId    = (args.length == 3) ? args[2] : null;

        System.out.println("[Scalive] REPL server starts at port " + port);
        final ServerSocket server = new ServerSocket(port);

        // Need to start a new thread because:
        // - ServerSocket#accept blocks until a connection comes in
        // - VirtualMachine#loadAgent at the client does not return until this
        //   agentmain method returns
        // - The client only connects to the server after VirtualMachine#loadAgent
        //   returns
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Socket client = server.accept();  // Block until a connection comes in
                    Server.serve(client, jarpath, clId);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        server.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
}<commit_msg>Close server immediately after accepting the connection we need<commit_after>package scalive;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.net.ServerSocket;
import java.net.Socket;

public class Agent {
    /**
     * @param agentArgs <jarpath> <server port> [class loader id]
     *
     * jarpath is the absolute path this directory:
     *
     * {{{
     * jarpath/
     *   scalive-agent.jar
     *   scalive-client.jar
     *   scalive-repl.jar
     *
     *   2.10.3/
     *     scala-library.jar
     *     scala-compiler.jar
     *     scala-reflect.jar
     *
     *   [Other Scala versions]
     * }}}
     */
    public static void agentmain(String agentArgs, Instrumentation inst) throws IOException {
        final String[] args    = agentArgs.split(" ");
        final String   jarpath = args[0];
        final int      port    = Integer.parseInt(args[1]);
        final String   clId    = (args.length == 3) ? args[2] : null;

        System.out.println("[Scalive] REPL server starts at port " + port);
        final ServerSocket server = new ServerSocket(port);

        // Need to start a new thread because:
        // - ServerSocket#accept blocks until a connection comes in
        // - VirtualMachine#loadAgent at the client does not return until this
        //   agentmain method returns
        // - The client only connects to the server after VirtualMachine#loadAgent
        //   returns
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Socket client = server.accept();  // Block until a connection comes in
                    server.close();                   // Accept no other clients
                    Server.serve(client, jarpath, clId);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
{'fraction_non_alphanumeric': 0.09670886075949367, 'fraction_numerical': 0.004050632911392405, 'mean_word_length': 1.6322451698867422, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704104', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1014, 'n_words': 300}