Skip to content

deno.exit() with Oak lib issue #9030

@FrageDev

Description

@FrageDev

Hi,

I setup a web server with Oak and I have a specific route where the route return a JSON then close the socket and close the process.

My route is :

.get('/api/reboot', async (ctx) => {
        await modules.reboot(ctx);
        await closeSocket();
})

The modules.reboot return the JSON with a "4" in the console after the ctx.response.body.
The function closeSocket() :

async function closeSocket() {
    try {
    modules.logger.warning(`1`);
    await delay(5000);
    modules.logger.warning(`2`);
    controller.abort();
    await delay(5000);
    modules.logger.warning(`3`);
    Deno.exit();}
    catch (error){
        console.log(error)
    }
}

I added some delay to do some experimentation. Here the console log of the app :

Wed Jan 06 2021 17:02:58 GMT+0100 (Romance Standard Time) | INFO         | Listening on https://localhost:8443
Wed Jan 06 2021 17:02:58 GMT+0100 (Romance Standard Time) | INFO         | GET https://localhost:8443/api/reboot from 127.0.0.1
Wed Jan 06 2021 17:02:58 GMT+0100 (Romance Standard Time) | INFO         | Reboot command recieved.
Wed Jan 06 2021 17:02:58 GMT+0100 (Romance Standard Time) | WARNING      | 4
Wed Jan 06 2021 17:02:58 GMT+0100 (Romance Standard Time) | WARNING      | 1
Wed Jan 06 2021 17:03:03 GMT+0100 (Romance Standard Time) | WARNING      | 2
Wed Jan 06 2021 17:03:08 GMT+0100 (Romance Standard Time) | WARNING      | 3

Here we can see the response body is supposed to be sent and now proceed to kill the server listen and then kill the process.

The issue is I don't receive the JSON from the request. If I'm not wrong when I open the console from Chrome I can see the request, I can see the request header and also a response header but no body.

Request Headers :

GET /api/reboot HTTP/1.1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36

Response Headers :

HTTP/1.1 200 OK
content-length: 16
content-type: application/json; charset=utf-8

I don't know if I made any mistakes or deno issue or oak issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questiona question about the use of Deno

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions