Browse Source

timeout on ssl handshake; band-aid on assertion failure

David Rose 21 years ago
parent
commit
0f33c2d118
1 changed files with 24 additions and 4 deletions
  1. 24 4
      panda/src/downloader/httpChannel.cxx

+ 24 - 4
panda/src/downloader/httpChannel.cxx

@@ -785,6 +785,12 @@ reached_done_state() {
     
     
   } else {
   } else {
     // Oops, we have to download the body now.
     // Oops, we have to download the body now.
+    // We shouldn't already be in the middle of reading some other
+    // body when we come here.
+    if (_body_stream != NULL) {
+      delete _body_stream;
+      _body_stream = (ISocketStream *)NULL;
+    }
     _body_stream = read_body();
     _body_stream = read_body();
     if (_body_stream == (ISocketStream *)NULL) {
     if (_body_stream == (ISocketStream *)NULL) {
       if (downloader_cat.is_debug()) {
       if (downloader_cat.is_debug()) {
@@ -1375,6 +1381,12 @@ run_setup_ssl() {
       << "performing SSL handshake\n";
       << "performing SSL handshake\n";
   }
   }
   _state = S_ssl_handshake;
   _state = S_ssl_handshake;
+
+  // We start the connect timer over again when we reach the SSL
+  // handshake.
+  _started_connecting_time = 
+    ClockObject::get_global_clock()->get_real_time();
+
   return false;
   return false;
 }
 }
 
 
@@ -1389,8 +1401,16 @@ bool HTTPChannel::
 run_ssl_handshake() {
 run_ssl_handshake() {
   if (BIO_do_handshake(_sbio) <= 0) {
   if (BIO_do_handshake(_sbio) <= 0) {
     if (BIO_should_retry(_sbio)) {
     if (BIO_should_retry(_sbio)) {
-      return true;
+      double elapsed =
+        ClockObject::get_global_clock()->get_real_time() -
+        _started_connecting_time;
+      if (elapsed <= get_connect_timeout()) {
+        // Keep trying.
+        return true;
+      }
+      // Time to give up on the handshake.
     }
     }
+
     downloader_cat.info()
     downloader_cat.info()
       << "Could not establish SSL handshake with " 
       << "Could not establish SSL handshake with " 
       << _request.get_url().get_server_and_port() << "\n";
       << _request.get_url().get_server_and_port() << "\n";
@@ -1852,9 +1872,9 @@ run_begin_body() {
   } else {
   } else {
     // We shouldn't already be in the middle of reading some other
     // We shouldn't already be in the middle of reading some other
     // body when we come here.
     // body when we come here.
-    nassertd(_body_stream == NULL) {
-      reset_to_new();
-      return false;
+    if (_body_stream != NULL) {
+      delete _body_stream;
+      _body_stream = (ISocketStream *)NULL;
     }
     }
     _body_stream = read_body();
     _body_stream = read_body();
     if (_body_stream == (ISocketStream *)NULL) {
     if (_body_stream == (ISocketStream *)NULL) {