sitemule / ILEastic

Embedded application server for ILE on IBM i
Apache License 2.0
58 stars 29 forks source link

Post Response Plugins not called on exception #102

Open m1h43l opened 3 years ago

m1h43l commented 3 years ago

If either plugin or endpoint sends an escape message/exception the post response plugins are not called anymore.

Depending on what you do in a post response plugin this may cause a memory leak. If a post plugin should release previously allocated memory and gets never called it could be a problem.

How about adding a boolean flag to the request or response struct if the request is still available for processing or has been aborted? And always execute the post response plugin. Then the post plugin could check if it actually needs to do something.

And the post response plugins are also not called if an previous plugin return *off.

        #pragma exception_handler(handleServletException, pResponse, _C1_ALL, _C2_MH_ESCAPE, _CTLA_HANDLE)
        matchingRouting = findRoute(request.pConfig, &request);
        if (matchingRouting) {
            request.routeId.Length = matchingRouting->routeId.Length;
            memcpy(request.routeId.String, matchingRouting->routeId.String, matchingRouting->routeId.Length); 
            request.pRouting = matchingRouting;
        }

        allSaysGo = runPlugins (request.pConfig->pluginPreRequest , &request , &response);
        if (allSaysGo) {
            if (pInstance->servlet) {
                pInstance->servlet (&request , &response);
            } else {
                runServletByRouting (&request , &response, matchingRouting ? matchingRouting->servlet:null);
            }
            runPlugins (request.pConfig->pluginPostResponse , &request , &response);
        }
        #pragma disable_handler

        putChunkEnd (&response);

        // Clean up this roundtrip 
        cleanupTransaction (&request , &response);