Problem/Motivation

https://www.drupal.org/pift-ci-job/331495
https://www.drupal.org/pift-ci-job/332599
https://www.drupal.org/pift-ci-job/331529
https://www.drupal.org/pift-ci-job/331547

DETAIL: Key (proname, proargtypes, pronamespace)=(rand, , 2200) already exists.: CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS

The #postgresql channel on freenode have confirmed that CREATE OR REPLACE contains a race condition.

Proposed resolution

Lock.

Remaining tasks

Commit ASAP.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#8 2751537_8.patch1.13 KBchx
#2 2751537_2.patch1021 byteschx

Comments

chx created an issue. See original summary.

chx’s picture

StatusFileSize
new1021 bytes
chx’s picture

Issue summary: View changes
chx’s picture

Issue summary: View changes
alexpott’s picture

Issue tags: +Needs tests

So the fail are consistent with a patch for https://www.drupal.org/project/dynamic_entity_reference? Is there a way to add a test to core for this?

chx’s picture

Nope. This is a race condition. It's literally impossible to test this. You'd need to fork and bomb PostgreSQL with CREATE FUNCTION calls and somehow ensure they fail without lock. My working theory is that DER testing is broken on PostgreSQL ATM because it yesterday it converted all of its WebTestBase to BrowserTestBase and apparently running two BrowserTestBase in parallel triggers this pretty reliably unlike WebTestBase did. That, actually, is the testing you are asking for. Core does not yet fail because there are so few BrowserTestBase classes. If my theory is correct then eventually it will begin to fail too.

alexpott’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

I'm happy to try this in 8.2.x just as long as we add a code comment - ideally will a link to some postgres docs on the known race condition.

I can accept that the effort to try to reproduce a race condition is not worth it. Are there any performance considerations we should be making with this change?

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB

> Are there any performance considerations we should be making with this change?

This is install time. Normal users don't install in parallel and PosgreSQL advisory locks were designed for speed. The only thing we can possibly hurt performance wise is the testbot and it's kicking a dead horse already: PostgreSQL testing is slow. Currently we are guaranteed to not hit this because if we were then it would die! In the future (if my theory is correct) we will hit this when BrowserTestBase is plenty but then we are talking of waiting for the grand total of four queries. AFAIK the race condition is not documented. Added a comment.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

This makes perfect sense to me - we're creating functions in the global database namespace and we're doing this is parallel. Given that this occurs in the installer there is not much to worry about here.

chx’s picture

alexpott’s picture

Title: PostgreSQL testing is broken » Race condition in \Drupal\Core\Database\Driver\pgsql\Install\Tasks
chx’s picture

Title: Race condition in \Drupal\Core\Database\Driver\pgsql\Install\Tasks » Race condition in \Drupal\Core\Database\Driver\pgsql\Install\Tasks breaks the testbot
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3130842 and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed 74b996c on 8.2.x
    Issue #2751537 by chx: Race condition in \Drupal\Core\Database\Driver\...

  • alexpott committed 3130842 on 8.1.x
    Issue #2751537 by chx: Race condition in \Drupal\Core\Database\Driver\...
jibran’s picture

Thank you @chx. DER is green on on d.o ci as well. https://www.drupal.org/node/2250343/qa

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.