Problems with Asynchronous callout and Fix

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Problems with Asynchronous callout and Fix

Postby tstalzer » Mon Mar 05, 2007 7:59 am


we are working on an application using WebServices, SciSockets, PlatformFunctions, etc - all the "nice stuff". Sometimes we encounter various problems with the asynchronous future calls (Usually raceconditions during shutdown). To fix these issues (sure helps that everything is in Smalltalk...), we changed the following coding in VA.

BTW - we are still using 7.0.1 in the project.

Code: Select all
!AcoCoroutineFuture privateMethods !


   "Put the resource group back in the resource pool"
   | fStub |
   resourceGroup := nil.
   (fStub := self futureStub) isNil ifFalse: [
      fStub reinitialize.
      resourceManager addGroup: fStub resourceGroup.
   ].! !"Extended Edition of PlatformFunction"!

!PlatformFunction privateMethods !

asyncCallWithFuture: future originalObjects: anArray

   "Answer the future object. The future object must have already allocated the resources. Copy the
    parameters to the asyncblock before the call"

   future asyncBlock   isNil ifTrue: [
      "TS - prevent a primitive failed because the block may be nil during shutdown"
      ^ future
   self primitiveAsyncCallSetUp: anArray asyncBlock: future asyncBlock inFuture: future.
   future thread startExecution.

   ^future! !

!AcoFuture privateMethods !


   "Signal that thread has completed execution. Allow processes waiting on the
    value to retreive it"

   self futureStub isNil ifTrue: [
      ^ AcoError new errorCode: ACORESOURCESLOST

   ^self futureStub errorValue isNil
      ifTrue: [returnValue := self primitiveCopyAsyncParametersBack: self asyncBlock]
      ifFalse: [
         returnValue := AcoError new errorCode: ACOEXCEPTIONHAPPENED.
         returnValue getGpInfoString: self thread.
         self futureStub errorValue: nil]! !

!AcoFutureStub privateMethods !


   "This method is called when the asynchronous call completes"
   directedMessage receiver isNil ifTrue: [
      "The receiver has been removed. Might happen during race conditions"
      ^ nil.
   ^directedMessage send! !
Posts: 65
Joined: Mon Oct 16, 2006 12:07 am
Location: Palma de Mallorca - Spain

Postby wembley » Tue Mar 06, 2007 5:33 am

Thomas -

Thanks for sending your updates along to us. I'll look into the issue you are having with race conditions. Are there any particular conditions that seem to cause the race conditions? You mentioned 'shutdown' -- do you mean when you shutdown your packaged image? How do you go about doing that?

Regards, John
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Postby tstalzer » Tue Mar 06, 2007 9:04 am

Hi John

Our application may be deployed as a GUI, Headless or Service application. The application uses SciSockets as a WebService server. Especially on the GUI application, if the user selects close (Either the "X" or button linked to "closeWidget"), the close of the sockets is forked (as the Socket operations cannot be called in the UIProcess). Now, even if we wait a couple of seconds, the sockets may still be working during the closing of the applications and events may come in after the Futurecalls have been "deinitialized".

As you can see in the code, the "fixes" are to test, if the futureStub is available, blocks are available, etc.

Posts: 65
Joined: Mon Oct 16, 2006 12:07 am
Location: Palma de Mallorca - Spain

Re: Problems with Asynchronous callout and Fix

Postby benvandijk » Mon Mar 03, 2008 8:36 am

Hi Thomas,

Thanks for the fixes.
We are currently experiencing the same problems when we try to stop running images.
We are running 7.5.0 as a NT service with webservices and HTTP server.

Greetings, Ben.
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: Problems with Asynchronous callout and Fix

Postby nchillo » Thu Sep 10, 2009 8:14 am

Is there any reason why this fix is not included in version 7.5 or 8.0?
We are having problems with asynchronous calls and wonder if this is the fix we need.
Posts: 9
Joined: Mon Nov 03, 2008 4:37 am

Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest