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

v1.3.0 breaks block-call semantics of PG::Connection #454

Closed
askreet opened this issue May 9, 2022 · 1 comment
Closed

v1.3.0 breaks block-call semantics of PG::Connection #454

askreet opened this issue May 9, 2022 · 1 comment

Comments

@askreet
Copy link

askreet commented May 9, 2022

Looking at the code, it seems like an oversight, but PG::Connection#initialize was previously implemented entirely in C, ending with this code:

if (rb_block_given_p()) {
    return rb_ensure(rb_yield, self, pgconn_finish, self);
}

In v1.3.0, the class function new is replaced with Ruby code here.

def new(*args, **kwargs)
	conn = self.connect_start(*args, **kwargs ) or
		raise(PG::Error, "Unable to create a new connection")

	raise(PG::ConnectionBad, conn.error_message) if conn.status == PG::CONNECTION_BAD

	conn.send(:async_connect_or_reset, :connect_poll)
end

The C implementation retains the semantics in connect_start (including a comment on 308 explaining it's role), but the block is not passed from new to connect_start in order to be called on line 326.

An example of some code that previously worked:

PG::Connection.open(admin_database_url) do |c|
  c.exec("DROP DATABASE #{database_name}")
end

With v1.3.0 and later, the inner block is not called.

@larskanis
Copy link
Collaborator

Yes, this is an oversight. I'll fix this.

larskanis added a commit that referenced this issue May 18, 2022
This was an oversight, when implementing the async interface of pg-1.3.0.

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

No branches or pull requests

2 participants