balderdashy / balderdashy/sails

Async helpers called synchronously fail silently

Open
#4,668 6 comments 0 reactions 0 assignees View on GitHub
helpful info or workaround question
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: 1.1
**Node version**: v10.15.1
**NPM version**: 6.4.1
**DB adapter name**: N/A
**DB adapter version**: N/A
**Operating system**: OSX


# Observed

Normal (async) helpers called without `await` keyword fail silently in production environments.

When `process.env.NODE_ENV !== 'PRODUCTION'`, [parley](https://www.npmjs.com/package/parley) prints the following warning to stderr:
```
WARNING: A function that was initially called over 15 seconds
ago has still not actually been executed. Any chance the
source code is missing an "await"?

To assist you in hunting this down, here is a stack trace:
...
```

# Expected

Helper code should run without blocking the caller.

A parallel with normal javascript would be that an `async` function called from synchronous code will still execute. From the node REPL:
```
> (async () => console.log('hi'))()
hi
```

# Recreating

Example project at https://github.com/alxndrsn/sailsjs-helper-silent-fail; see README for usage details.

# Notes

It is actually stated in the [helper docs](https://sailsjs.com/documentation/concepts/helpers#?synchronous-usage) that async helpers called without the `await` keyword _will not run_. Despite this, I still find the behaviour surprising.

Contributor guide

Open the contributing guide

Research direction

Start with the README in the linked reproduction project and the Sails helper documentation, especially the synchronous-usage section. Compare the documented behavior with the production behavior and parley warning, then determine the intended execution semantics and tests needed to show that synchronous calls behave as expected without blocking the caller.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.