-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Migrate from callbacks to async/await #3559
Conversation
Since this code can end up loaded in browsers when using client side plugins, avoid use of ES6 syntax features such as arrow functions until MSIE support is finally dropped.
…tall(), uninstall() We cannot use arrow functions in this file, because code in /src/static can end up being loaded in browsers, and we still support IE11.
Also fixed a bug where the system would make a request to the central server for the plugin list for every search even if the list was already cached.
Use real `async` instead of async.js where applicable. The `getPluginTests()` function was never truly async anyway because it only contains calls to synchronous `fs` modules.
`getPadAccess()` (src/node/padaccess.js) is now "promise only", resolving to `true` or `false` as appropriate, and throwing an exception if there's an error. The two call sites (padreadonly.js and importexport.js) updated to match.
Promisified methods: - get() - set() - findKeys() - getSub() - setSub() - remove() - doShutdown()
Removed the 's' for consistency with the other `doesFooExist()` manager calls. Retained an alias for plugins that might be using it.
Removed the 's' for consistency with the other `doesFooExist()` manager calls. Retained an alias for plugins that might be using it.
The function is now iterative rather than recursive.
Converted those functions that API.js still depends on, and others that at this point are never called via the nodeback mechanism.
This patch also contains significant refactoring relating to error checking of arguments supplied to the functions (e.g. rev) facilitated by use of `throw` instead of nodeback errors.
Also converted the handler functions that depend on checkAccess() into async functions too. NB: this commit needs specific attention to it because it touches a lot of security related code!
also fixes a missing await calling `.createAuthor` in db/Pad.js
- removed possible issue with failing to sanitize `padName` if `padId` was also supplied - removed unnecessary `try` block - simplified API and function name matching tests
950eae5
to
b723ef0
Compare
This change is in preparation of the future async refactoring by Ray. It tries to extract as many changes in boolean conditions as possible, in order to make more evident identifying eventual logic bugs in the future work. This proved already useful in at least one case. BEWARE: this commit exposes an incoherency in the DB API, in which, depending on the driver used, some functions can return null or undefined. This condition will be externally fixed by the final commit in this series ("db/DB.js: prevent DB layer from returning undefined"). Until that commit, the code base may have some bugs.
Extracted from Ray's work.
22c9cb9
to
60decc3
Compare
Hi, the PR is almost ready to be integrated. I just need a review from @ray. While writing async, some boolean expressions where made stricter (e.g.
I need a review on points 1 and 2. If Ray recognizes 1 as his beloved brainchild, and thinks that 2 may complete it, I'll fold the two changes and merge the PR. |
I think your If you like, I'm happy to audit all calls to I was going to suggest that just testing for |
That's true: using However, in its current status on The main pain point is probably ueberDB, but I do not want to digress. On commenting lax comparison: in async-PR, I agree, indeed I had already put such a comment in SessionManager.js: /*
* In some cases, the db layer could return "undefined" as well as "null".
* Thus, it is not possible to perform strict null checks on group2sessions.
* In a previous version of this code, a strict check broke session
* management.
*
* See: https://github.com/ether/etherpad-lite/issues/3567#issuecomment-468613960
*/
if (!group2sessions || !group2sessions.sessionIDs) { I think we have to decide what to do with AuthorManager, as well. All the original comparisons were lax, but if you have a look at d520e28 (which, I remember, just extracts changes made on async), all but one were made strict. Could this introduce latent bugs, as well?
That would be welcome: in that case we could reach a more coherent situation. If you do not have time, or if we want to postpone this, I can also make a ugly proposal in the name of pragmatism:
If you think it makes sense, I can compare develop with the asynchronous version, and worsen its purity in the name of compatibility. |
I've got time to do that audit. How (and where) would you prefer to see any relevant commits made? |
For reference, here's a comparison of ueberDB2's behaviour with DirtyDB
MySQL
|
ueberDB2 can return either undefined or null for a missing key, depending on which DB driver is used. This patch changes the promise version of the API so that it will always return null.
I found an alternate solution - see 32cebc4 |
Nice. Pulled in with ac7663c. |
It's done. I think it's worth citing from the commit message:
|
This PR represents the line of work that refactors Etherpad to use
async
/await
calls instead of callbacks, vastly simplifying the code, as per #3540.This represents a vast change, and by its nature requires a lot of testing, hence its WIP status. It is currently deployed on https://beta.etherpad.org. It will be merged as soon as deemed sufficiently stable.
It has the priority over other work: present and future PRs, in case of conflicting changes, will need to rebase themselves over this work.
The development is by contributor @raybellis.
The branch will be periodically force-pushed if needed, please update often.