Github user jpeach commented on a diff in the pull request:
https://github.com/apache/trafficserver/pull/779#discussion_r69363166
--- Diff: plugins/experimental/ts_lua/ts_lua.c ---
@@ -116,6 +116,69 @@ TSRemapDeleteInstance(void *ih)
return;
}
+void
+TSRemapOSResponse(void *ih, TSHttpTxn rh, int os_response_type)
+{
+ uint64_t req_id;
+
+ TSCont contp;
+ lua_State *L;
+
+ ts_lua_main_ctx *main_ctx;
+ ts_lua_http_ctx *http_ctx;
+ ts_lua_cont_info *ci;
+
+ ts_lua_instance_conf *instance_conf;
+
+ TSDebug(TS_LUA_DEBUG_TAG, "[%s] os response function and type - %d",
__FUNCTION__, os_response_type);
+
+ instance_conf = (ts_lua_instance_conf *)ih;
+ req_id = __sync_fetch_and_add(&ts_lua_http_next_id, 1);
+
+ main_ctx = &ts_lua_main_ctx_array[req_id % TS_LUA_MAX_STATE_COUNT];
+
+ TSMutexLock(main_ctx->mutexp);
+
+ http_ctx = ts_lua_create_http_ctx(main_ctx, instance_conf);
+
+ http_ctx->txnp = rh;
+ http_ctx->rri = NULL;
+ http_ctx->remap = 0;
+ http_ctx->has_hook = 0;
+
+ ci = &http_ctx->cinfo;
+ L = ci->routine.lua;
+
+ contp = TSContCreate(ts_lua_http_cont_handler, NULL);
+ TSContDataSet(contp, http_ctx);
+
+ ci->contp = contp;
+ ci->mutex = TSContMutexGet((TSCont)rh);
+
+ lua_getglobal(L, TS_LUA_FUNCTION_OS_RESPONSE);
+ if (lua_type(L, -1) != LUA_TFUNCTION) {
+ TSMutexUnlock(main_ctx->mutexp);
+ return;
+ }
+
+ ts_lua_set_cont_info(L, NULL);
+ if (lua_pcall(L, 0, 1, 0) != 0) {
+ TSError("[ts_lua] lua_pcall failed: %s", lua_tostring(L, -1));
+ }
+
+ lua_pop(L, 1);
+
+ if (http_ctx->has_hook) {
+ TSDebug(TS_LUA_DEBUG_TAG, "[%s] has txn hook -> adding txn close hook
handler to release resources", __FUNCTION__);
+ TSHttpTxnHookAdd(rh, TS_HTTP_TXN_CLOSE_HOOK, contp);
--- End diff --
If you do both remap and os_response, would you end up with a double free?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---