All Endpoints unreachable when registering a new one

Today I noticed one thing in my Asterisk (version 13.29 and 16.7):
My scenario is: I have PJSIP with realtime using ODBC on Postgres.
When I create a new endpoint in my database and register it, all the other endpoints that were registered in the server become unreachable, like this example output in asterisk’s console:
(endpoints 1001 and 1002 were already registered, then I created the endpoint 1003 and registered it)

[Mar  3 17:50:11]     -- Added contact 'sip:1003@172.16.16.25:5060;transport=UDP;rinstance=e9faec14588ce7c9' to AOR '1003' with expiration of 3600 seconds
[Mar  3 17:50:11]   == Endpoint 1001 is now Unreachable
[Mar  3 17:50:11]   == Endpoint 1002 is now Unreachable
[Mar  3 17:50:21]   == Endpoint 1003 is now Reachable
[Mar  3 17:50:21]     -- Contact 1003/sip:1003@172.16.16.25:5060;transport=UDP;rinstance=e9faec14588ce7c9 is now Reachable.  RTT: 11.752 msec

It only happens when I register a recently created endpoint. If I register a endpoint that was already registered before nothing abnornal happens.

Obs: The unreachable endpoints are not deleted from the table “ps_contacts”, and even show when I type “pjsip show contacts”. But if I try to make a call to them, I receive the message that they are unavaiable.

I’ve already have the logs of “debug level 99” and “pjsip set logger on”, but I didn’t found anything different on them, if needed I will post them here.

You might try moving the contact storage to local AstDB, in your sorcery.conf file [res_pjsip] section.

So from:

contact=realtime,ps_contacts

To:

contact=astdb,registrator

Changed it, restarted asterisk and registered a new endpoint, the same behavior happened, all the other endpoints became unreachable. Do I have to configure anything specific for AstDB?

You may be experiencing a filed issue[1]. If you apply the change there, does it alter things?

[1] https://issues.asterisk.org/jira/browse/ASTERISK-28056

I tried to configure a new endpoint entirely from pjsip.conf file, followed by a “pjsip reload” and registering this new endpoint, by doing so no other endpoint became unreachable. So now I am certanly that the error is in my database (but the contacts are still on the database).
I will post my database structure (it was created with alembic, but I have some custom columns on the ps_endpoints table), and in the meantime I will recompile asterisk with the changes of [1] described by @jcolp

ps_endpoints table:
https://pastebin.com/LFC0Kg41

ps_aors table:
https://pastebin.com/8EA6NY6W

ps_auth table:
https://pastebin.com/ehvQKJfB

And my sorcery.conf file:
https://pastebin.com/xPea25YN

I’ve patched the changes in file “res/res_pjsip/pjsip_options.c”, line 1670: } else if(!aor){

Recompiled res_pjsip module and followed the steps same as before and the endpoints didn’t became unreachable anymore.

Thank you again for addressing the issue this fast @jcolp. Will this bug be fixed in the next versions of asterisk?

I know of noone actively working on the issue, and the individual did not publish the change with some feedback I provided up for code review. It therefore needs someone to take it through the process, make changes, etc.