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

isc_cancel_events returns error invalid events id (handle) (code: 335545021) if event is (no longer) queued [CORE4794] #5092

Closed
firebird-automations opened this issue May 16, 2015 · 7 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @mrotteveel

Is related to CORE4756

Related to CORE4756:

Cancelling an event that is not currently queued will return error 335545021 ("invalid events id (handle)"). This is a deviation from the behavior in Firebird 2.5.4 and earlier which allows this.

Sample code that reproduces this (Jaybird 3/JNA so it is close to the native API):

/******************/
JnaDatabase db = factory.connect(connectionInfo);
db.attach();

FbClientLibrary lib = db.getClientLibrary();
ISC_STATUS[] statusVector = new ISC_STATUS[20];
SimpleEventHandler eventHandler = new SimpleEventHandler();

final JnaEventHandle eventHandle = new JnaEventHandle("TEST_EVENT_A", eventHandler, db.getEncoding());
int size = lib.isc_event_block(eventHandle.getEventBuffer(), eventHandle.getResultBuffer(), (short) 1, eventHandle.getEventNameMemory());
eventHandle.setSize(size);

// Queue event
lib.isc_que_events(statusVector, db.getJnaHandle(), eventHandle.getJnaEventId(), (short) eventHandle.getSize(), eventHandle.getEventBuffer().getValue(), eventHandle.getCallback(), eventHandle.getResultBuffer().getValue());
System.out.printf("Status: %s %s%n", statusVector[0], statusVector[1]);
// Event will notify almost immediately for initial setup.
Thread.sleep(50);

// Cancel (no event queued right now)
lib.isc_cancel_events(statusVector, db.getJnaHandle(), eventHandle.getJnaEventId());
System.out.printf("Status: %s %s%n", statusVector[0], statusVector[1]);
/******************/

With the 2.5.4 fbclient.dll this prints:
Status: 1 0
Status: 1 0

With 3.0.0.31839:
Status: 1 0
Status: 1 335545021

The asynchronous nature of events makes it hard to guarantee that an event is still queued when you cancel it. As such cancelling a no longer queued event should not be considered an error (at most it should be a warning). This is also what 2.5.4 does (interface.cpp, GDS_CANCEL_EVENTS):

	// If the event exists, tell the remote server to cancel it,
	// and delete it from the list

	Rvnt\* event = find\_event\(port, \*id\);
	if \(event\) \{
		send\_cancel\_event\(event\);
	\}

Commits: 867ef82 FirebirdSQL/fbt-repository@bcbea3f

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Link: This issue is related to CORE4756 [ CORE4756 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

environment: Windows 8.1 64 bit, Firebird 3.0.0.31839_x64

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Version: 3.0 Beta 2 [ 10586 ]

Version: 3.0 Beta 1 [ 10332 ] =>

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

It was rather suspicious solution to silently ignore wrong ID in isc_cancel_events(). One can pass hell knows what (starting with not initialized variable) as event id into cancelation routine and be happy that he does not que for some events any more. Letting user ignore error when due to async nature of events event already happened and should not be canceled seems to be slightly better choice, but let's be backward compatible with ISC API.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 3.0 Beta 2 [ 10586 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

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

2 participants