Discussion:
How to catch 502 Error
Velusamy, Gandhimathi
2017-09-24 01:35:01 UTC
Permalink
Hi,
I am working on Trafficserver-7.0.0.

In my plugin I want to handle the dead origin server.

I am trying to read the HTTP Transaction status through “TSHttpHdrStatusGe()t” after the function call TSHttpTxnServerRespGet() results in success.

but I could not get it success in both “TS_EVENT_HTTP_SEND_RESPONSE_HDR" and TS_EVENT_HTTP_READ_RESPONSE_HDR” event handlers.
I am able to get ServerState as “5” when the Origin Server is down in “TS_EVENT_HTTP_SEND_RESPONSE_HDR” event handler. Other than this information, is there any information I could use for handling Origin server down or What API I have to use for checking Origin Server down message?



Thanks
Gandhimathi
Alan Carroll
2017-09-25 16:55:27 UTC
Permalink
It should be possible to detect this the SEND_RESPONSE_HDR_HOOK. Be sure
you've attached to that hook, to make sure you get the event at the
appropriate time.

On Sat, Sep 23, 2017 at 8:35 PM, Velusamy, Gandhimathi <
Post by Velusamy, Gandhimathi
Hi,
I am working on Trafficserver-7.0.0.
In my plugin I want to handle the dead origin server.
I am trying to read the HTTP Transaction status through
“TSHttpHdrStatusGe()t” after the function call TSHttpTxnServerRespGet()
results in success.
but I could not get it success in both “TS_EVENT_HTTP_SEND_RESPONSE_HDR"
and TS_EVENT_HTTP_READ_RESPONSE_HDR” event handlers.
I am able to get ServerState as “*5”* when the Origin Server is down in
“TS_EVENT_HTTP_SEND_RESPONSE_HDR” event handler. Other than this
information, is there any information I could use for handling Origin
server down or What API I have to use for checking Origin Server down
message?
Thanks
Gandhimathi
Velusamy, Gandhimathi
2017-09-26 00:48:53 UTC
Permalink
Hi Alan Carroll,

Thanks for your response.

Here is my observation:




I guess as there is no response from the server, the buffer has nothing and if I try to use it for getting status, it is throwing error and causing it to crash. I have managed to use server state to catch the server unavailability. But could not get the status code.

My code is like this :
Code:
case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
{
TSMutexLock(map_mutex22);
ss= TSHttpTxnServerStateGet(txn);
TSDebug("balancer", " Send response [%" PRIu64 "] %d", sid, ss);
if (TS_SUCCESS == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) {
TSMLoc loc = TSMimeHdrFieldFind(hdr_bufp, hdr_loc, "Content-Length", -1);
rd.status_code = TSHttpHdrStatusGet(hdr_bufp, hdr_loc);
TSDebug("balancer", " [%" PRIu64 "] %d %s", sid, rd.status_code, TSHttpHdrReasonLookup(rd.status_code));
TSHandleMLocRelease(hdr_bufp, hdr_loc, loc);
}
else if (TS_ERROR == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) {
rd.status_code = TSHttpHdrStatusGet(hdr_bufp, hdr_loc);
TSDebug("balancer", " Send response Error [%" PRIu64 "]%d ", sid, rd.status_code) ;
TSHandleMLocRelease(hdr_bufp, TS_NULL_MLOC,hdr_loc);
}
TSMutexUnlock(map_mutex22);
}
break;

Output:


Here I stopped the apache server at 192.168.31.2 for testing. The server at 192.168.51.2 is running and print the status code both at TS_EVENT_HTTP_READ_RESPONSE_HDR and TS_EVENT_HTTP_SEND_RESPONSE_HDR event handlers.


[Sep 25 19:33:23.875] Server {0x7f80093b2700} DIAG: (balancer) 192.168.51.2 <- http://192.168.11.206/SDNCache.pdf
[Sep 25 19:33:23.940] Server {0x7f80093b2700} DIAG: (balancer) [0] 200 1619186 OK
[Sep 25 19:33:23.940] Server {0x7f80093b2700} DIAG: (balancer) Send response [0] 3
[Sep 25 19:33:23.940] Server {0x7f80093b2700} DIAG: (balancer) [0] 200 OK
[Sep 25 19:33:24.164] Server {0x7f80093b2700} DIAG: (balancer) Server 192.168.51.2 is at 3 Reward 0
[Sep 25 19:33:24.178] Server {0x7f80092b0700} DIAG: (balancer) 192.168.31.2 <- http://192.168.11.206/SDNCache.pdf
[Sep 25 19:33:24.200] Server {0x7f80092b0700} DIAG: (balancer) Send response [1] 5
FATAL: InkAPI.cc<http://inkapi.cc>:3910: failed assertion `sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS`
traffic_server: Aborted (Signal sent by tkill() 12369 65534)
traffic_server - STACK TRACE:
bin/traffic_server(_Z19crash_logger_invokeiP9siginfo_tPv+0x8e)[0x4ad78e]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10340)[0x7f800b7d3340]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x39)[0x7f800aa10cc9]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7f800aa140d8]
/usr/local/lib/libtsutil.so.7(+0x292c1)[0x7f800c8362c1]
/usr/local/lib/libtsutil.so.7(+0x27565)[0x7f800c834565]
bin/traffic_server(TSHttpHdrStatusGet+0x2d)[0x4ca3dd]
/usr/local/libexec/trafficserver/balancer.so(+0xa9f6)[0x7f7fdb5619f6]
bin/traffic_server(_ZN15INKContInternal12handle_eventEiPv+0xbb)[0x4c2f5b]
bin/traffic_server(_ZN6HttpSM17state_api_calloutEiPv+0x1ad)[0x5afb3d]
bin/traffic_server(_ZN6HttpSM20setup_error_transferEv+0x3d)[0x5b185d]
bin/traffic_server(_ZN6HttpSM14set_next_stateEv+0x75d)[0x5b4add]
bin/traffic_server(_ZN6HttpSM32call_transact_and_set_next_stateEPFvPN12HttpTransact5StateEE+0x32)[0x5a3982]
bin/traffic_server(_ZN6HttpSM25handle_server_setup_errorEiPv+0x229)[0x5a5d89]
bin/traffic_server(_ZN6HttpSM32state_send_server_request_headerEiPv+0x15a)[0x5b0cda]
bin/traffic_server(_ZN6HttpSM12main_handlerEiPv+0xbd)[0x5b635d]
bin/traffic_server(_Z15write_to_net_ioP10NetHandlerP18UnixNetVConnectionP7EThread+0x1365)[0x750075]
bin/traffic_server(_ZN10NetHandler12mainNetEventEiP5Event+0x2a4)[0x741a04]
bin/traffic_server(_ZN7EThread7executeEv+0x9c2)[0x774a82]
bin/traffic_server[0x77366a]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8182)[0x7f800b7cb182]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f800aad447d]


When I checked with TS_EVENT_HTTP_SEND_RESPONSE_HDR handler with out accessing HDR status,
if (TS_ERROR == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) condition is getting true.


Thanks
Gandhimathi


On Sep 25, 2017, at 11:55 AM, Alan Carroll <***@oath.com<mailto:***@oath.com>> wrote:

It should be possible to detect this the SEND_RESPONSE_HDR_HOOK. Be sure you've attached to that hook, to make sure you get the event at the appropriate time.
James Peach
2017-09-26 15:03:59 UTC
Permalink
Post by Velusamy, Gandhimathi
Hi Alan Carroll,
Thanks for your response.
I guess as there is no response from the server, the buffer has nothing and if I try to use it for getting status, it is throwing error and causing it to crash. I have managed to use server state to catch the server unavailability. But could not get the status code.
{
TSMutexLock(map_mutex22);
ss= TSHttpTxnServerStateGet(txn);
TSDebug("balancer", " Send response [%" PRIu64 "] %d", sid, ss);
if (TS_SUCCESS == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) {
I think you want TSHttpTxnClientRespGet(), which is the response the server will deliver back to the client.
Post by Velusamy, Gandhimathi
TSMLoc loc = TSMimeHdrFieldFind(hdr_bufp, hdr_loc, "Content-Length", -1);
rd.status_code = TSHttpHdrStatusGet(hdr_bufp, hdr_loc);
TSDebug("balancer", " [%" PRIu64 "] %d %s", sid, rd.status_code, TSHttpHdrReasonLookup(rd.status_code));
TSHandleMLocRelease(hdr_bufp, hdr_loc, loc);
}
else if (TS_ERROR == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) {
rd.status_code = TSHttpHdrStatusGet(hdr_bufp, hdr_loc);
TSDebug("balancer", " Send response Error [%" PRIu64 "]%d ", sid, rd.status_code) ;
TSHandleMLocRelease(hdr_bufp, TS_NULL_MLOC,hdr_loc);
}
TSMutexUnlock(map_mutex22);
}
break;
Here I stopped the apache server at 192.168.31.2 for testing. The server at 192.168.51.2 is running and print the status code both at TS_EVENT_HTTP_READ_RESPONSE_HDR and TS_EVENT_HTTP_SEND_RESPONSE_HDR event handlers.
[Sep 25 19:33:23.875] Server {0x7f80093b2700} DIAG: (balancer) 192.168.51.2 <- http://192.168.11.206/SDNCache.pdf
[Sep 25 19:33:23.940] Server {0x7f80093b2700} DIAG: (balancer) [0] 200 1619186 OK
[Sep 25 19:33:23.940] Server {0x7f80093b2700} DIAG: (balancer) Send response [0] 3
[Sep 25 19:33:23.940] Server {0x7f80093b2700} DIAG: (balancer) [0] 200 OK
[Sep 25 19:33:24.164] Server {0x7f80093b2700} DIAG: (balancer) Server 192.168.51.2 is at 3 Reward 0
[Sep 25 19:33:24.178] Server {0x7f80092b0700} DIAG: (balancer) 192.168.31.2 <- http://192.168.11.206/SDNCache.pdf
[Sep 25 19:33:24.200] Server {0x7f80092b0700} DIAG: (balancer) Send response [1] 5
FATAL: InkAPI.cc:3910: failed assertion `sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS`
traffic_server: Aborted (Signal sent by tkill() 12369 65534)
bin/traffic_server(_Z19crash_logger_invokeiP9siginfo_tPv+0x8e)[0x4ad78e]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10340)[0x7f800b7d3340]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x39)[0x7f800aa10cc9]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7f800aa140d8]
/usr/local/lib/libtsutil.so.7(+0x292c1)[0x7f800c8362c1]
/usr/local/lib/libtsutil.so.7(+0x27565)[0x7f800c834565]
bin/traffic_server(TSHttpHdrStatusGet+0x2d)[0x4ca3dd]
/usr/local/libexec/trafficserver/balancer.so(+0xa9f6)[0x7f7fdb5619f6]
bin/traffic_server(_ZN15INKContInternal12handle_eventEiPv+0xbb)[0x4c2f5b]
bin/traffic_server(_ZN6HttpSM17state_api_calloutEiPv+0x1ad)[0x5afb3d]
bin/traffic_server(_ZN6HttpSM20setup_error_transferEv+0x3d)[0x5b185d]
bin/traffic_server(_ZN6HttpSM14set_next_stateEv+0x75d)[0x5b4add]
bin/traffic_server(_ZN6HttpSM32call_transact_and_set_next_stateEPFvPN12HttpTransact5StateEE+0x32)[0x5a3982]
bin/traffic_server(_ZN6HttpSM25handle_server_setup_errorEiPv+0x229)[0x5a5d89]
bin/traffic_server(_ZN6HttpSM32state_send_server_request_headerEiPv+0x15a)[0x5b0cda]
bin/traffic_server(_ZN6HttpSM12main_handlerEiPv+0xbd)[0x5b635d]
bin/traffic_server(_Z15write_to_net_ioP10NetHandlerP18UnixNetVConnectionP7EThread+0x1365)[0x750075]
bin/traffic_server(_ZN10NetHandler12mainNetEventEiP5Event+0x2a4)[0x741a04]
bin/traffic_server(_ZN7EThread7executeEv+0x9c2)[0x774a82]
bin/traffic_server[0x77366a]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8182)[0x7f800b7cb182]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f800aad447d]
When I checked with TS_EVENT_HTTP_SEND_RESPONSE_HDR handler with out accessing HDR status,
if (TS_ERROR == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) condition is getting true.
Thanks
Gandhimathi
Post by Velusamy, Gandhimathi
It should be possible to detect this the SEND_RESPONSE_HDR_HOOK. Be sure you've attached to that hook, to make sure you get the event at the appropriate time.
Velusamy, Gandhimathi
2017-09-26 15:38:24 UTC
Permalink
Hi James Peach,

Thanks for your response.

Yes. Now it is giving me the status by using TSHttpTxnClientRespGet().

Thanks
Gandhimathi


I think you want TSHttpTxnClientRespGet(), which is the response the server will deliver back to the client.
Loading...