From 37c8da7d830185a74788c50baaa8cb060295040f Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 1 Sep 2006 21:29:43 +0000 Subject: [PATCH] doing better job of propogating network errors up the stack git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@774 9efc2488-bf62-4759-914b-345cdb29e865 --- src/gateway/osrf_json_gateway.c | 10 ++++++++++ src/libstack/osrf_app_session.c | 2 ++ src/libstack/osrf_stack.c | 5 +++++ src/libtransport/transport_client.c | 8 +++++++- src/libtransport/transport_client.h | 1 + src/libtransport/transport_session.c | 1 + src/utils/socket_bundle.c | 2 +- 7 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/gateway/osrf_json_gateway.c b/src/gateway/osrf_json_gateway.c index 213ea52..3e15742 100644 --- a/src/gateway/osrf_json_gateway.c +++ b/src/gateway/osrf_json_gateway.c @@ -164,6 +164,16 @@ static int osrf_json_gateway_method_handler (request_rec *r) { double starttime = get_timestamp_millis(); int req_id = osrf_app_session_make_req( session, NULL, method, api_level, mparams ); + + + if( req_id == -1 ) { + osrfLogError(OSRF_LOG_MARK, "I am unable to communcate with opensrf..going away..."); + /* we don't want to spawn an intense re-forking storm + * if there is no jabber server.. so give it some time before we die */ + sleep(1); + exit(1); + } + osrf_message* omsg = NULL; int statuscode = 200; diff --git a/src/libstack/osrf_app_session.c b/src/libstack/osrf_app_session.c index e9b88e1..008f25f 100644 --- a/src/libstack/osrf_app_session.c +++ b/src/libstack/osrf_app_session.c @@ -525,6 +525,8 @@ int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int session->remote_service, session->session_id, t_msg->recipient, string ); retval = client_send_message( session->transport_handle, t_msg ); + + if( retval ) osrfLogError(OSRF_LOG_MARK, "client_send_message failed"); free(string); message_free( t_msg ); diff --git a/src/libstack/osrf_stack.c b/src/libstack/osrf_stack.c index ee3254c..2e5027c 100644 --- a/src/libstack/osrf_stack.c +++ b/src/libstack/osrf_stack.c @@ -17,6 +17,11 @@ int osrf_stack_process( transport_client* client, int timeout ) { timeout = 0; } + if( client->error ) { + osrfLogWarning(OSRF_LOG_MARK, "transport_client had trouble reading from the socket.."); + return -1; + } + if( ! client_connected( client ) ) return -1; return 0; diff --git a/src/libtransport/transport_client.c b/src/libtransport/transport_client.c index c5f30e3..4c91581 100644 --- a/src/libtransport/transport_client.c +++ b/src/libtransport/transport_client.c @@ -61,6 +61,7 @@ transport_client* client_init( char* server, int port, char* unix_path, int comp client->session = init_transport( server, port, unix_path, client, component ); client->session->message_callback = client_message_handler; + client->error = 0; return client; } @@ -87,6 +88,7 @@ int client_connected( transport_client* client ) { int client_send_message( transport_client* client, transport_message* msg ) { if(client == NULL) return 0; + if( client->error ) return -1; return session_send_msg( client->session, msg ); } @@ -115,6 +117,7 @@ transport_message* client_recv( transport_client* client, int timeout ) { int x; if( (x = session_wait( client->session, -1 )) ) { osrfLogWarning(OSRF_LOG_MARK, "session_wait returned failure code %d\n", x); + client->error = 1; return NULL; } } @@ -131,8 +134,11 @@ transport_message* client_recv( transport_client* client, int timeout ) { int wait_ret; while( client->m_list->next == NULL && remaining >= 0 ) { - if( (wait_ret= session_wait( client->session, remaining)) ) + if( (wait_ret= session_wait( client->session, remaining)) ) { + client->error = 1; + osrfLogWarning(OSRF_LOG_MARK, "session_wait returned failure code %d: setting error=1\n", wait_ret); return NULL; + } ++counter; diff --git a/src/libtransport/transport_client.h b/src/libtransport/transport_client.h index 4d37cc4..aa0b921 100644 --- a/src/libtransport/transport_client.h +++ b/src/libtransport/transport_client.h @@ -31,6 +31,7 @@ typedef struct message_list_struct transport_message_node; struct transport_client_struct { transport_message_list* m_list; transport_session* session; + int error; }; typedef struct transport_client_struct transport_client; diff --git a/src/libtransport/transport_session.c b/src/libtransport/transport_session.c index 3de292f..9351c20 100644 --- a/src/libtransport/transport_session.c +++ b/src/libtransport/transport_session.c @@ -117,6 +117,7 @@ int session_wait( transport_session* session, int timeout ) { int ret = socket_wait( session->sock_mgr, timeout, session->sock_id ); if( ret ) { + osrfLogError(OSRF_LOG_MARK, "socket_wait returned error code %d", ret); session->state_machine->connected = 0; } return ret; diff --git a/src/utils/socket_bundle.c b/src/utils/socket_bundle.c index 73cecb4..a8f2aad 100644 --- a/src/utils/socket_bundle.c +++ b/src/utils/socket_bundle.c @@ -661,8 +661,8 @@ int _socket_handle_client_data(socket_manager* mgr, socket_node* node) { if(read_bytes == 0) { /* socket closed by client */ if(mgr->on_socket_closed) { mgr->on_socket_closed(mgr->blob, sock_fd); - return -1; } + return -1; } return 0; -- 2.11.0