Bug 118924

Summary: kontact deletes contacts on exit
Product: [Applications] kontact Reporter: Thomas Bettler <thomas.bettler>
Component: contactsAssignee: Tobias Koenig <tokoe>
Status: RESOLVED FIXED    
Severity: major CC: ach, claudius.wettstein, p92, toma, wolfram.wagner
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Thomas Bettler 2005-12-23 22:39:36 UTC
Version:            (using KDE KDE 3.5.0)
Installed from:    Gentoo Packages
OS:                Linux

Steps to reproduce:
1. open kontact
2. open new mail message
3. type anything i.e. "test@hotmail.com" into the To field
4. change to contacts view (leaving the composer open)
5. close kontact

Result:
There is no crash, everthing seems ok, 
BUT .kde/share/apps/kabc/std.vcf 
(the addressbook resource) instantly becomes size 0 bytes!

This is very annoying, I'd really apreciate fixing this!
Comment 1 Raphaël Pinson 2006-01-02 12:40:52 UTC
Same thing on a Kubuntu 5.10 box with KDE 3.5.0. 

In step 3, I confirm _any_ text will reproduce the bug (not only email addresses).

Very annoying indeed :(
Comment 2 Raphaël Pinson 2006-01-02 12:57:22 UTC
Here is the Kontact trace when I run these steps (## are comments) :

## checking std.vcf

isabelle@isabelle:~/Desktop$ ls -l ~/.kde/share/apps/kabc/
...
-rw-r--r--  1 isabelle isabelle 33817 2006-01-02 12:56 std.vcf
...

## opening kontact
isabelle@isabelle:~/Desktop$ kontact
kdecore (KAction): WARNING: KAction::plugAccel(): call to deprecated action.
kdecore (KAction): WARNING: KAction::plugAccel(): call to deprecated action.
kdecore (KAction): WARNING: KAction::plugAccel(): call to deprecated action.
QLayout::addChildLayout: layout already has a parent
WeaverThreadLogger: thread (ID: 1) suspended.
WeaverThreadLogger: thread (ID: 2) suspended.
WeaverThreadLogger: thread (ID: 3) suspended.
WeaverThreadLogger: thread (ID: 4) suspended.
kabc: WARNING: address format database incomplete (no format for locale C found). Using default address formatting.
## Kontact started, creating new email message now && switching to contacts view
## Exiting Kontact
QWidget::setMaximumSize: (unnamed/RecipientComboBox) The largest allowed size is (32767,32767)
kabc: WARNING: address format database incomplete (no format for locale C found). Using default address formatting.
Weaver dtor: destroying inventory.
WeaverThreadLogger: thread (ID: 1) destroyed.
WeaverThreadLogger: thread (ID: 2) destroyed.
WeaverThreadLogger: thread (ID: 3) destroyed.
WeaverThreadLogger: thread (ID: 4) destroyed.
Weaver dtor: done


## checking for std.vcf presence

isabelle@isabelle:~/Desktop$ ls -l ~/.kde/share/apps/kabc/
...
-rw-r--r--  1 isabelle isabelle     0 2006-01-02 12:53 std.vcf
...
Comment 3 Raphaël Pinson 2006-02-17 13:53:26 UTC
This big bug seems to be still around on KDE 3.5.1 ...
Comment 4 Altmenorg 2006-03-06 16:13:58 UTC
*** This bug has been confirmed by popular vote. ***
Comment 5 Altmenorg 2006-03-06 16:21:43 UTC
I can confirm this too on kubuntu 6.04, kde 3.5.1.

I only performed steps 1,2,3,5 to reproduce.
No need for set 4 in my case.
Comment 6 Achim Bohnet 2006-03-06 16:38:42 UTC
This sound like #120093.

    http://bugs.kde.org/120093

Whenever I have unfinished mail open on exit and start kontact again,
addressbook is truncated to size zero too :(

Happend today again :(  Kubuntu/Dapper with KDE 3.5.1.

Achim
Comment 7 Ismail Onur Filiz 2006-03-06 17:31:18 UTC
*** Bug 120093 has been marked as a duplicate of this bug. ***
Comment 8 Tom Albers 2006-03-06 23:03:58 UTC
Did the following commit fix this or is it unrelated?
-----------

SVN commit 512375 by pfeiffer:
 
No news (feedback) is good news, I guess. Nobody complained and
I haven't lost any addresses anymore. So let's get some more
testers.
 
Can somebody merge this into trunk?
 
 
 M  +146 -35   file/resourcefile.cpp  
 M  +13 -5     file/resourcefile.h  
 M  +155 -52   net/resourcenet.cpp  
 M  +12 -4     net/resourcenet.h
Comment 9 Raphaël Pinson 2006-03-07 13:51:00 UTC
I built kdelibs with this patch again, didn't solve the issue. I rebuilt kdepim on top of the new kdelibs obtained with this patch and didn't solve the bug even after restarting KDE. So for me this patch doesn't fix this bug.
Comment 10 Till Adam 2006-03-07 19:29:47 UTC
SVN commit 516587 by tilladam:

Don't attempt to (synchronously) save if we are still async loading, because 
otherwise the following fascinating chain of events is possible:

- Kontact shutdown unloads parts, which destructs the addressbook part
- StdAddressbook is deleted, which clears the addressbook
- before the clear the composer in KMail finds a closed addressbook,
  thus opens it again, triggering an asyncLoad.
- that asyncLoad triggers a KIO::Job, which starts, but never finishes
- KApplication's static deletion of the newly opened addressbook leads
  to a saveAll, which leads to a save() of the file resource, which 
  iterates over the StdAddressbook which has already been cleared, but
  not re-loaded yet, since we are waiting for the KIO copy job of the 
  temp file to finish, thus writing out a 0 byte file

The reason why the kio job doesn't finish is that it has already been
killed, at this point (we are in static deletion of the application,
after all).

I'm suspecting that StdAddressbook should not call saveAll() from the
destructor. A wise man (David Faure) once told me "Intelligent dtors are
bad", and I've since painfully learned a few times how right he was.
I'm afraid to change that in branch, though, no telling what relies
on it. Also KMail's composer auto-save should not hit the KeyResolver,
which loads the addressbook, but that's only marginally related.

This fixed the 0-file issue described in the bug, but it's still writing
out spurious empty entries, sometimes, to the file resource. Will debug
that next.

BUG: 118924
CCMAIL: tokoe@kde.org


 M  +4 -0      resourcefile.cpp  


--- branches/KDE/3.5/kdelibs/kabc/plugins/file/resourcefile.cpp #516586:516587
@@ -302,6 +302,10 @@
   if (d->mIsSaving) {
     abortAsyncSaving();
   }
+  if ( d->mIsLoading ) {
+    kdWarning(5700) << "Aborted save() because we're still asyncLoad()ing!" << endl;
+    return false;
+  }
 
   // create backup file
   QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
Comment 11 Raphaël Pinson 2006-03-08 02:32:39 UTC
This works :)
Thank you so much Till. Adding the patch to kdelibs in Kubuntu. Hopefully it'll be up soon :)
Comment 12 Tom Albers 2006-03-08 10:17:47 UTC
*** Bug 121023 has been marked as a duplicate of this bug. ***
Comment 13 Tom Albers 2006-03-08 10:18:07 UTC
*** Bug 121078 has been marked as a duplicate of this bug. ***
Comment 14 Tom Albers 2006-03-08 10:29:17 UTC
Op woensdag 8 maart 2006 10:09, schreef Till Adam:
> On Wednesday 08 March 2006 09:34, Tobias Koenig wrote:
> > On Wed, Mar 08, 2006 at 09:23:24AM +0100, Till Adam wrote:
> > Hi Till,
> >
> > > Yeah, those are nice, but I think they should actually be used by
> > > the software, not just disgruntled humans. When we detect a 0 byte
> > > addressbook during loading, we could restore the newest backup on
> > > loading, maybe? Tobias?
> >
> > I don't know... it would be nice for the user indeed. Do you have a
> > patch available?
>
> No, but it should not be hard to do. Any JuniorJob volunteers reading
> this? :)


I can have a look, but not before mid next week probably. 

Toma
Comment 15 Thomas Bettler 2006-03-12 12:26:25 UTC
AFAIK, this commit didn't affect KDE-3.5.2 - is this right?

Could you also provide a fix for KDE-3.5.2 of this nasty bug? - Thank you a lot!
Comment 16 Neil.Harsant 2006-06-12 06:34:20 UTC
Bug shows up in Boxed SuSE 10.1 also. Kontact Version 1.2 on KDE 3.5.1 Level "a".
Attempted to restore backup copy of ~/.kde/share/apps/kabc/std.vcf 
This worked when a backup of the std.vcf was copied into a newly created user's
home. ( i.e. Kontact's addressbook then correctly showed all the addresses ) 
This didn't work when the file is restored to the original user's home.
Presume there are further files that need to be restored or repaired.
Has anyone done a Howto on restoring the addressbook from a backup?
Comment 17 Will Stephenson 2007-01-30 08:58:53 UTC
Neil: upstream at https://bugzilla.novell.com/show_bug.cgi?id=200177 .

An update is in the works.
Comment 18 Will Stephenson 2007-02-01 14:34:24 UTC
I meant https://bugzilla.novell.com/show_bug.cgi?id=212203 .