Module development: Stuck in "access phase: 6" when calling a function from a shared library (written in Go)

Robin Monjo robinmonjo at gmail.com
Thu Apr 21 22:32:00 UTC 2016


Hello all,

I’m trying to build a nginx module both with C code and Go code. The idea is to create a Go code that is compiled into a shared library and then call function of this lib from a basic nginx module C code.

Here is my handler (in C), taken from this guide: https://www.airpair.com/nginx/extending-nginx-tutorial <https://www.airpair.com/nginx/extending-nginx-tutorial>

———————————————————————————————————————— 
static ngx_int_t ngx_http_l_handler(ngx_http_request_t *r) {
  if (r->main->internal) { //already processed
    return NGX_DECLINED;
  }

  r->main->internal = 1; // mark as processed
  
  ngx_table_elt_t *h;
  h = ngx_list_push(&r->headers_out.headers);
  h->hash = 1;
  ngx_str_set(&h->key, "X-NGINX-Tutorial");
  ngx_str_set(&h->value, "Hello World!");
  
  HandleRequest(); // calling go code here :)
  
  return NGX_DECLINED;
}
———————————————————————————————————————— 

It just inject a HTTP header. It works fine, without the “HandleRequest()” call. “HandleRequest()” is a function coming from the Go code. This function is empty and does nothing. With this call, nginx just never finishes the response and is stuck. Here are the logs:

———————————————————————————————————————— 
2016/04/21 21:57:01 [debug] 33#0: epoll: fd:6 ev:0001 d:00007FC064EA9010
2016/04/21 21:57:01 [debug] 33#0: accept on 0.0.0.0:8888, ready: 0
2016/04/21 21:57:01 [debug] 33#0: posix_memalign: 00000000007426F0:512 @16
2016/04/21 21:57:01 [debug] 33#0: *1 accept: 127.0.0.1:43842 fd:3
2016/04/21 21:57:01 [debug] 33#0: *1 event timer add: 3: 60000:1461275881230
2016/04/21 21:57:01 [debug] 33#0: *1 reusable connection: 1
2016/04/21 21:57:01 [debug] 33#0: *1 epoll add event: fd:3 op:1 ev:80002001
2016/04/21 21:57:01 [debug] 33#0: timer delta: 17268
2016/04/21 21:57:01 [debug] 33#0: worker cycle
2016/04/21 21:57:01 [debug] 33#0: epoll timer: 60000
2016/04/21 21:57:01 [debug] 33#0: epoll: fd:3 ev:0001 d:00007FC064EA91B0
2016/04/21 21:57:01 [debug] 33#0: *1 http wait request handler
2016/04/21 21:57:01 [debug] 33#0: *1 malloc: 0000000000742900:1024
2016/04/21 21:57:01 [debug] 33#0: *1 recv: fd:3 78 of 1024
2016/04/21 21:57:01 [debug] 33#0: *1 reusable connection: 0
2016/04/21 21:57:01 [debug] 33#0: *1 posix_memalign: 0000000000742D10:4096 @16
2016/04/21 21:57:01 [debug] 33#0: *1 http process request line
2016/04/21 21:57:01 [debug] 33#0: *1 http request line: "GET / HTTP/1.1"
2016/04/21 21:57:01 [debug] 33#0: *1 http uri: "/"
2016/04/21 21:57:01 [debug] 33#0: *1 http args: ""
2016/04/21 21:57:01 [debug] 33#0: *1 http exten: ""
2016/04/21 21:57:01 [debug] 33#0: *1 http process request header line
2016/04/21 21:57:01 [debug] 33#0: *1 http header: "User-Agent: curl/7.35.0"
2016/04/21 21:57:01 [debug] 33#0: *1 http header: "Host: 127.0.0.1:8888"
2016/04/21 21:57:01 [debug] 33#0: *1 http header: "Accept: */*"
2016/04/21 21:57:01 [debug] 33#0: *1 http header done
2016/04/21 21:57:01 [debug] 33#0: *1 event timer del: 3: 1461275881230
2016/04/21 21:57:01 [debug] 33#0: *1 rewrite phase: 0
2016/04/21 21:57:01 [debug] 33#0: *1 test location: "/"
2016/04/21 21:57:01 [debug] 33#0: *1 using configuration "/"
2016/04/21 21:57:01 [debug] 33#0: *1 http cl:-1 max:1048576
2016/04/21 21:57:01 [debug] 33#0: *1 rewrite phase: 2
2016/04/21 21:57:01 [debug] 33#0: *1 post rewrite phase: 3
2016/04/21 21:57:01 [debug] 33#0: *1 generic phase: 4
2016/04/21 21:57:01 [debug] 33#0: *1 generic phase: 5
2016/04/21 21:57:01 [debug] 33#0: *1 access phase: 6

// stuck here nothing will happen next ...
———————————————————————————————————————— 

I have no warning or error during the compilation of my module. Any idea of where this behaviour could come from ?

Regards,
Robin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20160422/834cfcd6/attachment.html>


More information about the nginx-devel mailing list