parse-community / parse-community/parse-server

Abort Cloud Code execution when server has timed out

Open
#6,681 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type:feature
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

Is your feature request related to a problem? Please describe.

Given a Parse Server is setup to have a request timeout set of 10s:

const httpServer = require('http').createServer(app);
httpServer.timeout = 10 * 1000;

When a Cloud Code function is called and takes 20s to execute, NodeJS destroys the socket after 10s, but the Cloud Code function keeps on executing. Some cloud code functions are just wasting resources in that case and it should be possible to abort them in a controlled manner.

Describe the solution you'd like

Add a status parameter to the request object of the Cloud Code function that is the current status of the request. When a request is aborted due to socket timeout, the status should be updated accordingly.

This allows it to query the request object at different points during the Cloud Code execution and abort the execution in a controlled manner without causing data inconsistencies.

The callback function of the server timeout can be used to update the request status:

httpServer.setTimeout(10 * 1000, {
   request.status = Parse.Cloud.FunctionRequest.Status.Timeout;  // pseudo code
});

Inside the Cloud Code function the status can be observed and processing aborted in a controlled manner:

Parse.Cloud.define("example", async (request) => {
   // Do something
   // ...

   if (request.status == Parse.Cloud.FunctionRequest.Status.Timeout) {
      // Abort here
      return;
   }

   // Do more
   // ...
});
Describe alternatives you've considered

Any ideas for alternatives?

Additional context

Originally posted as a question on SO, but since it seems that there is no current solution to this, opening an issue here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by tracing the Parse.Cloud.define request lifecycle and the httpServer timeout callback described in the issue; done means a timed-out request exposes an updated status to Cloud Code so execution can detect it and stop in a controlled manner.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.