# Issue with KeepAlive

**URL:** <https://www.ruby-forum.com/t/issue-with-keepalive/244894>\
**Category:** NGINX\
**Created:** [July 4, 2016, 7:29pm UTC](https://www.ruby-forum.com/t/issue-with-keepalive/244894 "2016-07-04T19:29:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 4, 2016, 7:29pm UTC](https://www.ruby-forum.com/t/issue-with-keepalive/244894/1 "2016-07-04T19:29:04Z")

</div>

Hi all,

I need help on managing KeepAlive on my nginx webservice.

Seeing error logs seems that many keepalive HTTP request are discarded  
by  
Nginx. On client side this behaviour seems to be a timeout.

This is my code:

if(strlen(session-\>response) \> 0) {  
b-\>pos = (u\_char \*)session-\>response;  
b-\>last = (u\_char \*)session-\>response + strlen(session-\>response);  
r-\>headers\_out.content\_type\_len = strlen(“application/json”) - 1;  
r-\>headers\_out.content\_type.data = (u\_char \*) “application/json”;  
r-\>headers\_out.status = NGX\_HTTP\_OK;

} else {  
b-\>pos = (u\_char \*)r-\>args.data;  
b-\>last = (u\_char \*)r-\>args.data + r-\>args.len;  
r-\>headers\_out.status = NGX\_HTTP\_NO\_CONTENT;

}  
r-\>headers\_out.content\_length\_n = strlen(session-\>response);

b-\>memory = 1;  
b-\>last\_buf = 1;

ftime(&end);  
felapsed=(int) (1000.0 \* (end.time - start.time) +  
(end.millitm - start.millitm));

ngx\_http\_send\_header(r);

ngx\_http\_output\_filter(r, &out);  
ngx\_http\_finalize\_request(r, r-\>headers\_out.status);

Sometimes i Send a 200 Ok and some other times 204.

On nginx error log I see:

2016/07/04 11:06:11 [debug] 11643#11643: \*13 http finalize request: 204,  
“/mopub\_bidr?” a:1, c:2  
2016/07/04 11:06:11 [debug] 11643#11643: \*13 http terminate request  
count:2  
2016/07/04 11:06:11 [debug] 11643#11643: \*13 http terminate cleanup  
count:2  
blk:0  
2016/07/04 11:06:11 [debug] 11643#11643: \*13 http finalize request: -4,  
“/mopub\_bidr?” a:1, c:2  
2016/07/04 11:06:11 [debug] 11643#11643: \*13 http request count:2 blk:0  
2016/07/04 11:06:11 [debug] 11643#11643: \*13 http posted request:  
“/mopub\_bidr?”

Someone can me explain what means “finalize request: -4” ? It’s an  
error?

Sometime into error log I found this error:

recv() not ready

and this seems the cause of client timeouts. how can I resolve it on  
nginx  
conf?

Thanks a lot for help

Stefano G.

Posted at Nginx Forum:

> **[Issue with KeepAlive](https://forum.nginx.org/read.php?2,268052,268052#msg-268052)**
>
> Hi all, I need help on managing KeepAlive on my nginx webservice. Seeing error logs seems that many keepalive HTTP request are discarded by Nginx. On client side this behaviour seems to be a timeout. This is my code: if(strlen(session-&gt
