Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cryptic error for chttpd_auth_cache:username #1821

Open
akircher opened this issue Dec 19, 2018 · 10 comments
Open

Cryptic error for chttpd_auth_cache:username #1821

akircher opened this issue Dec 19, 2018 · 10 comments

Comments

@akircher
Copy link

akircher commented Dec 19, 2018

I apologize if this is documented elsewhere, but I am seeing a lot of the error below on our production server. Is this okay? If not, is this an error in our code or in couchdb? To my knowledge none of our views/validation use a function called "username". Thank you in advance for your time.

[notice] 2018-12-19T23:46:43.281783Z [email protected] <0.332.0> -------- chttpd_auth_cache changes listener died no function clause matching chttpd_auth_cache:username(<<"e43caea614fb6e2250df47e4da043d64">>)(line:18$
[error] 2018-12-19T23:46:43.281838Z [email protected] emulator -------- Error in process <0.8490.6970> on node '[email protected]' with exit value:
{function_clause,[{chttpd_auth_cache,username,[<<"e43caea614fb6e2250df47e4da043d64">>],[{file,"src/chttpd_auth_cache.erl"},{line,183}]},{chttpd_auth_cache,changes_callback,2,[{file,"src/chttpd_auth_cache.erl"},{line,$

Expected Behavior

No notice or error is logged

Your Environment

This is running on Couch DB 2.2.0, Node 10.9.0, Ubuntu 16.04.5

@akircher akircher changed the title Cryptic error for chttpd_auth_cache Cryptic error for chttpd_auth_cache:username Dec 20, 2018
@wohali
Copy link
Member

wohali commented Dec 20, 2018

That's a definite bug - are you able to try Couch 2.3.0 to see if this is fixed?

@eiri
Copy link
Member

eiri commented Dec 20, 2018

This is not from a db's VDU, but from auth_cache. The field username of user's doc has to have org.couchdb.user: prefix.

This is not exactly a bug, more of exception not been handled gracefully, because assumption here is that validation on _users database should prevent creation of users without that prefix, so they can't get into the cache.

@akircher Check out for a doc e43caea614fb6e2250df47e4da043d64 in _users database or whatever database set in config's [chttpd_auth] as authentication_db.

@wohali
Copy link
Member

wohali commented Dec 20, 2018

@eiri agreed there should only be docs in _users with the org.couchdb.user: prefix, but we probably should catch the situation where the wrongly named doc is in that DB and not toss a function_clause error.

@eiri
Copy link
Member

eiri commented Dec 20, 2018

@wohali oh yeah, for sure, this is a good beginner-friendly defect to fix. Crashing the auth cache's changes reader on a misconfiguration is excessive, a log's warning on an invalid username and then ignore would be a better way to handle this.

@akircher
Copy link
Author

@eiri that did it! Not sure how a user got in there with that _id. We had some recent code changes that used 'force=true' as an option, maybe some type of automatic conflict resolution is what did it.

@popojargo
Copy link
Member

I'm working on a fix. What would be the proper place to add a test for that?

@jaydoane
Copy link
Contributor

@popojargo I don't see an obvious existing test file, so I would probably create a new one called test/chttpd_auth_cache_test.erl and add any new tests there. For a simple unit test, It's tempting to just add a test to chttpd_auth_cache.erl itself, but there are obscure interactions between meck and eunit that will occasionally prevent such tests from running when invoked via make eunit. YMMV.

@popojargo
Copy link
Member

@jaydoane I was planning on doing the following:

Test 1: Check if the user is removed from auth cache when it has a valid id
Test 2: Check if either the cache reader didn't crash or if the couch_log is called with my specific error message.

Since I started working with erlang yesterday, I might need few advices.

  1. Let's say I want to check the cache state, do I need to start the ets_lru cache in my test or start_couch() will automatically start it?
  2. For my second test, is it easy to check if the cache reader crashed or I can stick with the couch_log check? (I guess I could mock the logger)

@akircher
Copy link
Author

Update: deleting the user was not enough. I deleted the doc and am still getting the error. Maybe a purge will work.

@ghost
Copy link

ghost commented Apr 8, 2019

I'm hitting this as well (accidentally created a document in _users with a UUID instead of org.couchdb.user: while demoing Fauxton on our dev server.)
Deleting and calling _purge on this unwanted record got rid of this error message.

CouchDB 2.3.1

  • [Edit] we hit some other issues that I thought were related, but seem to be related to a domain change.

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

No branches or pull requests

5 participants