Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'send' of null - worker.terminate() BUG #400

Closed
JoshuaeKaiser opened this issue Jan 25, 2020 · 2 comments
Closed

Cannot read property 'send' of null - worker.terminate() BUG #400

JoshuaeKaiser opened this issue Jan 25, 2020 · 2 comments

Comments

@JoshuaeKaiser
Copy link

Using multer to produce a small proof of concept I came across this bug.

Node throws me an error 'Cannot read property 'send' of null '

app.post('/upload', async (req, response) => {
    let finalResponse = response;
    await upload(req, response, err => {
        fs.readFile(`./uploads/${req.file.originalname}`, async (error, data) => {
            interpretAndSend(data, finalResponse);
        });
    });
});

async function interpretAndSend(imgData, res) {
    await worker.load();
    await worker.loadLanguage('eng');
    await worker.initialize('eng');
    const {
        data: { text },
    } = await worker.recognize(imgData);
    await worker.terminate(); <----- Issue Here
    res.send(text);
}

The first time i call the route everything works fine. When i try to pass a file to the route a second time I get the error in the console. I managed to track it down to worker.terminate();

If I comment out worker.terminate(); then the app works fine, no idea what the route cause of it is.

@jeromewu
Copy link
Member

jeromewu commented Feb 2, 2020

When you can Worker.terminate(), it will terminate the child_process (web worker in browser) in the background, which makes this worker unusable, that's why it fails to execute in the second run.

@jeromewu jeromewu closed this as completed Feb 2, 2020
@ssengedonazil
Copy link

That the right solution .. for me thnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants