ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

serveStaticFile() only works sometimes

Open tombentley opened this issue 8 years ago • 4 comments

Maybe I'm doing something wrong, but using this code

import ceylon.http.server {
    newServer,
    AsynchronousEndpoint,
    isRoot
}
import ceylon.io {
    SocketAddress
}
import ceylon.http.server.endpoints {
    serveStaticFile
}
shared void bug() {
    value server = newServer {
        AsynchronousEndpoint {
            path = isRoot();
            service = serveStaticFile {
                externalPath = "README.txt";
            };
        }
    };
    server.start(SocketAddress("127.0.0.1",8080));
}

A get request to http://localhost:8080/ only seems to work about 50% of the time (often alternating working and not). When it doesn't work I see an empty 200 response.

tombentley avatar Jul 05 '16 15:07 tombentley

Looking at the test case [1], the only difference is that test uses a fat arrow "=>" to assign service.

p.s.: did you try to run the sdk tests, do they always pass ?

1: https://github.com/ceylon/ceylon-sdk/blob/master/test-source/test/ceylon/http/server/server.ceylon#L188

matejonnet avatar Jul 06 '16 08:07 matejonnet

The tests don't pass at all. The reason seems to be that the failing assertions are being executed on worker threads, so never propagate out of the test function being run on the main thread. :-(

tombentley avatar Jul 06 '16 08:07 tombentley

0b92c898f9fa50f4b0f05fd662169bf49e882c29 fixes the tests so that exceptions throw in the worker threads get rethrown from the main thread, resulting in the testServer test failing. I suspect a similar fix may be necessary for other tests.

tombentley avatar Jul 06 '16 09:07 tombentley

I tried your code and it worked in Chrome, Safari and Opera. Can you try again to see if it really doesn't work?

Papershine avatar Aug 09 '17 04:08 Papershine