Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Error with setPassword: The specified item already exists in the keychain. #127

Open
adeperio opened this issue Sep 28, 2018 · 3 comments
Open

Comments

@adeperio
Copy link

Hi

I am on node-keytar 4.2.1. Every so often, when I call setPassword, keytar sends back the following exception:

The specified item already exists in the keychain.

According to the docs I was expecting this function to update an existing item, or create a new keychain item if one doesn't exist. Is this the correct assumption? If so any ideas why I might be seeing this error.

Happens on some calls to setPassword, but on other calls it doesn't.

@adeperio adeperio changed the title The specified item already exists in the keychain. Error with setPassword: The specified item already exists in the keychain. Sep 28, 2018
@shiftkey
Copy link
Contributor

@adeperio which OS are you testing on?

@RMacfarlane
Copy link
Contributor

I've seen reports of this as well, on macOS 10.14.6. Is there any data I can collect to help diagnose the problem?

@RMacfarlane
Copy link
Contributor

Actually, I think I now understand what is happening in my case! I have several different processes that are reading and writing to the same keychain item. If writes occur pretty much simultaneously, then one will throw the duplicate item error during the second AddPassword here:

KEYTAR_OP_RESULT SetPassword(const std::string& service,
const std::string& account,
const std::string& password,
std::string* error) {
KEYTAR_OP_RESULT result = AddPassword(service, account, password,
error, true);
if (result == FAIL_NONFATAL) {
// This password already exists, delete it and try again.
KEYTAR_OP_RESULT delResult = DeletePassword(service, account, error);
if (delResult == FAIL_ERROR)
return FAIL_ERROR;
else
return AddPassword(service, account, password, error, false);
} else if (result == FAIL_ERROR) {
return FAIL_ERROR;
}
return SUCCESS;
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants