Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dropping network connection leads app to freeze if a remote db is open
Forum Updated to NodeBB v4.3 + New Features

Dropping network connection leads app to freeze if a remote db is open

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 159 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    Qt 6.4.0 on Ubuntu 22.04.
    I open a remote odbc connection:

    bool OdbcSql::connectToDB(QUrl host, QString database, QString username, QString password)
    {
        _host = host;
        _database = database;
        _username = username;
        _password = password;
    
        qInfo() << ID << "Trying to open database...";
        _db.setDatabaseName(QStringLiteral("Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1; Server=%1;Database=%2; Encrypt=No;").arg(host.url()).arg(database));
        _db.setUserName(username);
        _db.setPassword(password);
        _db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT=5;SQL_ATTR_LOGIN_TIMEOUT=5");
    
        bool ret = _db.open();
        if (ret) qInfo() << ID << "Database opened successfully";
        else qWarning() << ID << "Database opening failed:" << _db.lastError();
    
        return ret;
    }
    

    After a connection I try to simulate a network issue rejecting all traffic from/to the host using ufw. The whole application freezes forever (at least for over 5 minutes) in the QSqlQuery::exec() call:

    bool OdbcSql::retrieveNewOrders()
    {
        QString sql = QString("SELECT * FROM %1 WHERE mo_rilasciato='N' ORDER BY td_datord, td_numord;").arg(TABLE_NEW_ORDERS);
        QSqlQuery query(_db);
    
        if (!query.prepare(sql))
        {
            qWarning() << ID << "Prepare query failed" << sql;
            qWarning() << ID << query.lastError();
            return false;
        }
    
        query.exec(); // <----- IT NEVER RETURNS
        while (query.next())
        {
            if (query.isValid())
            {
                bool ret = _ordersDB->enqueueNewOrder(query.record());
                if (ret) setOrderProcessed(query.record(), true);
            }
        }
    
        return true;
    }
    

    How should I handle such a behavior?
    It never exits from that function, hence I can't even check the properties of the database.

    Z 1 Reply Last reply
    0
    • M Mark81

      Qt 6.4.0 on Ubuntu 22.04.
      I open a remote odbc connection:

      bool OdbcSql::connectToDB(QUrl host, QString database, QString username, QString password)
      {
          _host = host;
          _database = database;
          _username = username;
          _password = password;
      
          qInfo() << ID << "Trying to open database...";
          _db.setDatabaseName(QStringLiteral("Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1; Server=%1;Database=%2; Encrypt=No;").arg(host.url()).arg(database));
          _db.setUserName(username);
          _db.setPassword(password);
          _db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT=5;SQL_ATTR_LOGIN_TIMEOUT=5");
      
          bool ret = _db.open();
          if (ret) qInfo() << ID << "Database opened successfully";
          else qWarning() << ID << "Database opening failed:" << _db.lastError();
      
          return ret;
      }
      

      After a connection I try to simulate a network issue rejecting all traffic from/to the host using ufw. The whole application freezes forever (at least for over 5 minutes) in the QSqlQuery::exec() call:

      bool OdbcSql::retrieveNewOrders()
      {
          QString sql = QString("SELECT * FROM %1 WHERE mo_rilasciato='N' ORDER BY td_datord, td_numord;").arg(TABLE_NEW_ORDERS);
          QSqlQuery query(_db);
      
          if (!query.prepare(sql))
          {
              qWarning() << ID << "Prepare query failed" << sql;
              qWarning() << ID << query.lastError();
              return false;
          }
      
          query.exec(); // <----- IT NEVER RETURNS
          while (query.next())
          {
              if (query.isValid())
              {
                  bool ret = _ordersDB->enqueueNewOrder(query.record());
                  if (ret) setOrderProcessed(query.record(), true);
              }
          }
      
          return true;
      }
      

      How should I handle such a behavior?
      It never exits from that function, hence I can't even check the properties of the database.

      Z Offline
      Z Offline
      zeljko
      wrote on last edited by
      #2

      @Mark81 see sysctl net.ipv4.tcp_keepalive_time, you should reduce it to something reasonable for you (7200 secs is default afair).

      1 Reply Last reply
      1
      • M Mark81 has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved