NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.94k stars 1.69k forks source link

SIGSEGV Running on android #554

Open Jbiloki opened 5 years ago

Jbiloki commented 5 years ago

I am running the following server on android:

import android.util.Log;
import fi.iki.elonen.NanoHTTPD;

import java.io.IOException;
import java.util.Map;

public class TestServer extends NanoHTTPD{
    LiteEngine engine = null;
    public TestServer(LiteEngine engine) throws IOException {
        super(8080);
        System.out.println("\nRunning! Point your browsers to http://localhost:8080/ \n");
        this.engine = engine;
    }

    @Override
    public Response serve(IHTTPSession session) {
        String msg = "<html><body><h1>Server Started</h1>\n";
        Method method = session.getMethod();
        Log.i("Method hit.","In Serve");
        if(Method.POST.equals(method)){
            Map<String, String> params = session.getParms();
            if(params.get("query") != null){
                String lang = "en";
                String regionCode = "us";
                if(params.get("lang") != null){
                    lang = params.get("lang");
                }
                if(params.get("regionCode") != null){
                    regionCode = params.get("regionCode");
                }
                LiteQuery query = new LiteQuery(params.get("query"), "", "", lang, regionCode, "", true, engine.textUtil);
                LiteAnalysis processed = this.engine.analyzeSpeechSimple(query);
                Log.i("Processed: ", processed.toJsonString());
                return newFixedLengthResponse(processed.toJsonString());
            }
            else{
                return newFixedLengthResponse("Include a query param in your request to process");
            }
        }
        return newFixedLengthResponse(msg + "</body></html>\n");
    }

}

Which produces multiple warnings of:

W/System: A resource failed to call end.

Over time these warnings accumulate and the server fails with status:

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 23057 (NanoHttpd Reque), pid 22978