Filter virt_db: close backend for Init rejected
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 1 Jan 2010 20:47:31 +0000 (21:47 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 1 Jan 2010 20:47:31 +0000 (21:47 +0100)
Close backend filter session when Init rejected is received from it
(in which case it's not really closed yet). This will ensure we don't
run out of resources such as FDs in this case.

src/filter_virt_db.cpp

index aca2634..a7d0ae8 100644 (file)
@@ -236,31 +236,24 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
         {
             b->m_named_result_sets = true;
         }
-        if (!*res->result)
+        if (*res->result)
         {
-            error_code = YAZ_BIB1_DATABASE_UNAVAILABLE;
-            mp::util::get_init_diagnostics(res, error_code, addinfo);
-            BackendPtr null;
-            return null; 
+            m_backend_list.push_back(b);
+            return b;
+
         }
-    }
-    else
-    {
         error_code = YAZ_BIB1_DATABASE_UNAVAILABLE;
-        // addinfo = database;
-        BackendPtr null;
-        return null;
-    }        
-    if (init_package.session().is_closed())
+        mp::util::get_init_diagnostics(res, error_code, addinfo);
+    }
+    if (!init_package.session().is_closed())
     {
-        error_code = YAZ_BIB1_DATABASE_UNAVAILABLE;
-        // addinfo = database;
-        BackendPtr null;
-        return null;
+        Package close_package(b->m_backend_session, package.origin());
+        close_package.copy_filter(package);
+        close_package.session().close();
+        close_package.move(b->m_route);  // closing it
     }
-
-    m_backend_list.push_back(b);
-    return b;
+    BackendPtr null;
+    return null; 
 }
 
 void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)