Skip to content
Snippets Groups Projects
Commit a4299dba authored by David Faure's avatar David Faure
Browse files

Cancel session request if the task is deleted early.

E.g. due to losing the connection to the server.
Otherwise the request is processed later on, with no task to use that
session, and we end up with a session in m_reservedSession for ever, and
soon afterwards an infinite stream of
"Cancelling this request. Probably there is no more session available."

Might be related to:
CCBUG: 318098, 316541
(but for lack of debug output in these reports, I can't tell for sure)

FIXED-IN: 4.10.5
Reviewed-by: Kévin Ottens
parent 36d2afb4
No related branches found
No related tags found
No related merge requests found
......@@ -42,8 +42,11 @@ ResourceTask::ResourceTask( ActionIfNoSession action, ResourceStateInterface::Pt
ResourceTask::~ResourceTask()
{
if ( m_pool && m_session ) {
m_pool->releaseSession( m_session );
if ( m_pool ) {
if ( m_sessionRequestId )
m_pool->cancelSessionRequest( m_sessionRequestId );
if ( m_session )
m_pool->releaseSession( m_session );
}
}
......
......@@ -148,6 +148,12 @@ qint64 SessionPool::requestSession()
return requestNumber;
}
void SessionPool::cancelSessionRequest( qint64 id )
{
Q_ASSERT( id > 0 );
m_pendingRequests.removeAll( id );
}
void SessionPool::releaseSession( KIMAP::Session *session )
{
if ( m_reservedPool.contains( session ) ) {
......
......@@ -78,6 +78,7 @@ public:
void disconnect( SessionTermination termination = LogoutSession );
qint64 requestSession();
void cancelSessionRequest( qint64 id );
void releaseSession( KIMAP::Session *session );
ImapAccount *account() const;
......
......@@ -507,6 +507,49 @@ private slots:
server.quit();
}
void shouldHonorCancelRequest()
{
FakeServer server;
server.addScenario( QList<QByteArray>()
<< FakeServer::greeting()
<< "C: A000001 LOGIN \"test@kdab.com\" \"foobar\""
<< "S: A000001 OK User Logged in"
<< "C: A000002 CAPABILITY"
<< "S: * CAPABILITY IMAP4 IMAP4rev1 UIDPLUS IDLE"
<< "S: A000002 OK Completed"
<< "C: A000003 CAPABILITY"
<< "S: * CAPABILITY IMAP4 IMAP4rev1 UIDPLUS IDLE"
<< "X"
);
server.startAndWait();
ImapAccount *account = createDefaultAccount();
DummyPasswordRequester *requester = createDefaultRequester();
SessionPool pool( 1 );
pool.setPasswordRequester( requester );
QSignalSpy connectSpy( &pool, SIGNAL(connectDone(int,QString)) );
QSignalSpy sessionSpy( &pool, SIGNAL(sessionRequestDone(qint64,KIMAP::Session*,int,QString)) );
QSignalSpy lostSpy( &pool, SIGNAL(connectionLost(KIMAP::Session*)) );
// Initial connect should trigger only a password request and a connect
QVERIFY( pool.connect( account ) );
QTest::qWait( 100 );
QCOMPARE( connectSpy.count(), 1 );
QCOMPARE( sessionSpy.count(), 0 );
qint64 requestId = pool.requestSession();
// Cancel the request
pool.cancelSessionRequest( requestId );
// The request should not be processed anymore
QTest::qWait( 100 );
QCOMPARE( sessionSpy.count(), 0 );
}
void shouldBeDisconnectedOnAllSessionLost()
{
FakeServer server;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment