fireice-uk / xmr-stak

Free Monero RandomX Miner and unified CryptoNight miner
GNU General Public License v3.0
4.05k stars 1.79k forks source link

xmrstak does not closes the output stream of HTTP response #1117

Open alextrezvy opened 6 years ago

alextrezvy commented 6 years ago

v2.2.0. I'm writing the external watchdog (called 'mchecker') to detect when a miner fails. It already works with claymore and sgminer-gm, but fails with xmrstak. The reason is the output stream is not being closed, so the watchdog waits for the end of response until timeout exception is thrown. I know I can read only a small predefined amount bytes or parse the response to detect the closing 'HTML' tag, but I want to implement general approach. Here is how I read the response:

        String result = "";
        Socket s = new Socket(host, port);
        s.setSoTimeout(TIMEOUT);
        InputStream is = s.getInputStream();
        OutputStream os = s.getOutputStream();
        os.write(request.getBytes());
        os.flush();
        int read = 0;
        int cnt = 0;
        byte[] b = new byte[1024];
        while ((read = is.read()) >= 0) { 
            if ((cnt+1) > b.length) {
                b = Arrays.copyOf(b, b.length*2);
            }
            b[cnt++] = (byte)read;
        }
        result = new String(b);
alextrezvy commented 6 years ago

OK, I have worked around this bug by parsing the header 'Content-Length'. But you still may correct it.

psychocrypt commented 6 years ago

@fireice-uk Could you please have a look to this issu