Closed Soulike closed 2 years ago
Thanks for the report, It seems that this issue is not very harmful, but what do you suggest to fix it @Soulike? This is my proposal to fix it: https://github.com/telefonicaid/fiware-pep-steelskin/pull/478
Thanks for the report, It seems that this issue is not very harmful, but what do you suggest to fix it @Soulike?
Yes, we have exactly the same thought. Instead of calling loadTempate()
inside the callback of listen()
, we can call listen()
inside the callback of loadTempate()
to ensure roleTemplate
and requestTemplate
are loaded before the server starts to listen.
PR https://github.com/telefonicaid/fiware-pep-steelskin/pull/478 should solve this issue.
@Soulike what do you think?
PR #478 should solve this issue.
@Soulike what do you think?
👍Good job
Thanks! :)
Thus, I think the issue can now be closed.
I think there is a race condition in lib/services/validation.js.
When
initializeProxy()
is called, it registers middlewares includingvalidationProcess()
in validation.jshttps://github.com/telefonicaid/fiware-pep-steelskin/blob/7cb31b3f0817813719ae041be0697ca2e18e86a8/lib/fiware-pep-steelskin.js#L253
and
validationProcess()
asynchronously callscreateAccessRequest()
, in which readsroleTemplate
andrequestTemplate
https://github.com/telefonicaid/fiware-pep-steelskin/blob/7cb31b3f0817813719ae041be0697ca2e18e86a8/lib/services/validation.js#L64-L67
It means that
roleTemplate
andrequestTemplate
may be read when the proxy server starts listen.However, the initialization of
roleTemplate
andrequestTemplate
is asynchronously done in thelisten()
callback withvalidation.loadTemplates()
https://github.com/telefonicaid/fiware-pep-steelskin/blob/7cb31b3f0817813719ae041be0697ca2e18e86a8/lib/fiware-pep-steelskin.js#L280-L296
https://github.com/telefonicaid/fiware-pep-steelskin/blob/7cb31b3f0817813719ae041be0697ca2e18e86a8/lib/services/validation.js#L230-L241
It means that
roleTemplate
andrequestTemplate
are stillundefined
when the proxy server starts listen. If a request comes beforeloadTemplate()
loadsroleTemplate
andrequestTemplate
,createAccessRequest()
will getundefined
s.I found this but I don't know if the race is harmful. Thank you.