Races when using node.js, postgresql and knex.js

I have a node.js + express 4 + socket.io + postgresql (with knex.js) application. Its purpose is to send tasks to connected clients via socket.io for processing. This is how I implemented the qurey for fetching a new task for computation:

update data
  set status='computing'
  where id = (select id from data where status = 'new' limit 1)
  returning *

I used update with the returning option to assure, that operation of fetching task is atomic. The problem is that when there are multiple clients, they can request the task multiple times anyway.

This happens only when using knex.js library for building the queries. I suspect the reason to be the fact, that knex.js keeps pool of connections open. When debugging, it seems that my app is hitting the method that executes the query multiple times before any of the promises with the result resolve (and then it is the same for many of them). With ~20 clients connected, as many as 8 can get the same task in my application.

In the beginning I used pg-query module that just creates a db connection every time it is invoked and everything worked just fine. EDIT: I now found out that there are races with the second method as well. Just they just occur much less frequently.

So: what am I doing wrong? How can I improve my code/db to make it better.

As I found the answer in another question, asked differently I will just post it here. For future reference: Atomic UPDATE .. SELECT in Postgres