Hello guys.
I'm facing the following problem which seems to me a bug. Postgres version used - 13.7
 
1) Connection1:
create or replace function test_fn() returns text as $$
begin
  return 'version1';
end;
$$ language plpgsql;
 
2) Connection2:
begin;
select test_fn();
 test_fn
---------
 version1
(1 row)
 
3) Connection1:
create or replace function test_fn() returns text as $$
begin
  return 'version2';
end;
$$ language plpgsql;
 
4) Connection2:
select test_fn();
 test_fn
---------
 version1
(1 row)
 
So the question is why Connection2 does not see updated version of test_fn? I've looked at source code and found that system cache invalidations (PROCOID cache in this case) occurs in AcceptInvalidationMessages() call chain. This function is called in a plenty of places but not when we call function in a running transaction as in the example. My thought is that AcceptInvalidationMessages() should be called in xact.c --> StartTransactionCommand() for TBLOCK_INPROGRESS, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_SUBINPROGRESS cases. Am I right or is it not even a bug?