File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -349,6 +349,11 @@ async function invokeAction ({ actionRequestContext, logger }) {
349349 }
350350 }
351351 }
352+
353+ // if we run an action, we will restore the process.env after the call
354+ // we must do this before we load the action because code can execute on require/import
355+ const preCallEnv = { ...process . env }
356+ const originalCwd = process . cwd ( )
352357 // generate an activationID just like openwhisk
353358 process . env . __OW_ACTIVATION_ID = crypto . randomBytes ( 16 ) . toString ( 'hex' )
354359
@@ -417,6 +422,10 @@ async function invokeAction ({ actionRequestContext, logger }) {
417422 statusCode,
418423 body : { error : 'Response is not valid \'message/http\'.' }
419424 }
425+ } finally {
426+ logger . debug ( 'restoring process.env and cwd' )
427+ process . env = preCallEnv // restore the environment variables
428+ process . chdir ( originalCwd ) // restore the original working directory
420429 }
421430 } else {
422431 // this case the action returned an error object, so we should use it
You can’t perform that action at this time.
0 commit comments