-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Parse Server may expose HTTP routes before complete initialization #7527
Comments
Thanks for opening this issue!
|
Is this actually a bug or an enhancement? In other words, is there currently something not working with Parse Server (bug), or is it not usable for your specific use case (enhancement)? |
Heh, it's a little bit of both! It's a It's also a And it's a |
This sounds much like a bug. Thanks for explaining. Could you clarify this in the issue description? |
✔️ updated |
I classified this as a bug with severity S3 (normal), because:
|
Have you looked at let parseServer;
let expressServer;
export async function start(): Promise<void> {
await new Promise<void>((resolve, reject) => {
try {
parseServer = new ParseServer({
serverURL: 'http://localhost:1337/parse',
appId: 'someappid',
javascriptKey: 'somejavascriptkey',
masterKey: 'somemasterkey',
databaseURI: 'mongodb://localhost:27017/pase',
cloud: './cloud/main.js',
serverStartComplete: (error) => {
if (error) {
reject(error);
} else {
resolve();
}
},
});
} catch (e) {
reject(e);
}
});
const app = express();
app.use('/parse', parseServer.app);
return new Promise<void>((resolve, reject) => {
try {
expressServer = app.listen(1337, resolve);
} catch (e) {
reject(e);
}
});
} |
Hi @davimacedo, Thanks for your suggestion! Yes, that would solve part of the issue, but Cloud Codes will still load after the In general, performing For my LMK what would be your prefered approach and i'll submit a PR this week. |
Reading again the original issue, this sounds more like an infrastructure issue, because if the express app does not listen to the port yet, you probably wouldn't want to route external requests to the server instance yet. I can think of 3 design patterns that are usual in an infrastructure context:
For (a) I assume that it would be If However, regardless of that issue, there may be potential for improvement in the Parse Server constructor design, to give more versatility on the node level to control the readiness state, but that would probably be an enhancement that is separate from the aforementioned bug. If fixing the bug doesn't depend on a constructor redesign, I suggest to address the enhancement in a separate GitHub issue. |
This is a ParseServer issue. Express starts to listen to requests before ParseServer finished it's loading. Currently, it's not that of a big deal because overall, initialization is fairly quick 1-2 seconds. But in the case of Parse not being able to connect to Mongo, Parse and Express should not listen to requests before the server is ready OR report a healthy status when in reality any requests would fail due to the lack of database connection. Secondly, this issue/improvement is directly related to the Schema Migration PR. With the introduction of schema migrations, you definitively DONT want Cloud code to load before migrations are completed, and you don't want Express to listen to requests before Cloud code is loaded. Schema Migrations are quite fast, but if you have 50 Schemas to validate/update it may take a 10-15 seconds. The fixes/improvements proposed above would fix theses issues. |
I agree if one of the following is true, like I said above:
I think you confirmed that already in your previous comment:
Does the constructor need to change to fix the callback issue? |
Good question, IMO That said, I have no idea if thats the intended behaviour or not. If you don't insight about this, I'll have a look in I'm not sure any user would have BC break if we move it after Cloud is loaded. Side note for later: If we implement one of my suggestions above, i would also recommend deprecating in v6.0 I'll open a different issue when this issue is resolved to address this later. |
From what I can see, this is a bug. The docs say:
The server has not started if it has not loaded all of its modules. As such, if people are using this callback as intended (as you would in your case like Davi suggested), then they will currently face the issue of errors (what you originally described) because the callback is called too early. Fixing this would not be considered a breaking change, because it is a bug fix. My suggestion would be to fix this bug in this issue and treat the constructor change as an enhancement in a separate issue. This way we can also easily backport this fix to Parse Server 4.x. |
Ok, awesome! I'll submit a PR sometime soon ...
Ok. Do we keep one issue with two PRs? Otherwise I'll duplicate this issue to discuss the next steps. |
Yes, I suggest to split the enhancement into a separate issue and PR. This way we can fix the bug quicker and backport it to 4.x. It also allows to remodel the constructor with a deprecation (breaking change), should it be needed. |
I just discovered the issue. This lets us config AWS load balancer to check a specific route to know the instance status. |
If we are supporting this as a breaking change for V6, we could also remove
|
🎉 This change has been released in version 6.0.0-alpha.16 |
🎉 This change has been released in version 6.0.0-beta.1 |
🎉 This change has been released in version 6.0.0 |
This is amazing work guys ! My deploy scripts will be so happy 🥂 |
New Issue Checklist
Issue Description
Currently, all
ParseServer
initialization is done in theconstructor
and there is no way to ensure everything is ready before the app is loaded.The main issue(s)
Parse Server constructor will continue to do initialization tasks long after the constructor caller returns, and we have no way to await for its completion.
Server will start to listen to incoming http requests before CloudCode is loaded.
This can be bad in some case because
express
andParseServer
can get exposed to the world, before it have completed its initialization leading to client side errorsIdeally, we should refactor the
constructor
startup process into aasync start()
method that can be awaited on.Currently we see at occasion during rolling updates clients running cloud functions
Parse.Cloud.run('xyz')
and receivingParse.Error
Function XYZ does not exists
. This is caused by having the parseapi
mounted andexpress
running before all Cloud Code have a time to start.A few solutions
(A) Without introducing a BC Break
This solution is great as a compromise for now.. It's simple, and have no long term implications.
Add a
isReady()
function that return a promise that is resolved when the constructor has completed(B) Without introducing a BC Break, and a path forward
This solution is great long term solution.
Move constructor init into a
start()
method, and add aParseServerOption
autoStart: true
. Later in version6.0.0
we can defaultautoStart
tofalse
or ignore/deprecate the parameter(C) Pure and simple BC Break
Just put all constructor code into a
start()
and tell users they need to call it in the5.0.0
release notes(C) is obvisously a bit harsh 😆 ! LMK what you think and i can submit a PR for either (A) or (B)
Steps to reproduce
Actual Outcome
Expected Outcome
Failing Test Case / Pull Request
Environment
Server
Database
mingo
recent
gc
Client
js
4.5.4
Logs
Have a good day,
Samuel
The text was updated successfully, but these errors were encountered: