cancel
Showing results for 
Search instead for 
Did you mean: 

SAP NCo 3 multi-threaded use, User property in RfcConfigParameters gets zero'ed

david_burg
Participant
0 Kudos

I might not be using Begin.Context/EndContext right as I have concurrent threads using a mix of destinations (including multiple threads using the same destination), each doing without synchronization concurrent operation on what i thought would be their private Stateful connection.

The first symptom of trouble is that after a few -successful- calls, User property in RfcConfigParameters gets zero'ed. If a thread does another call on the RfcDestination instance it got, there will be a Repeat Logon failure exception because the user name ain't right anymore.

I don't know why the user name gets stamped with zeroes, I wonder if a SecureString or alike implementation is taking hold of the provided credentials, get the byte array backing the string and stamps over it with zeroes once done in fear of leaking the sensitive information. What doesn't add up however is that the password is still there, only the user property is zeroed.

I've attempted to workaround the issue by checking the RfcDestination Parameters property each time before using the RfcDestination, and if they do not match with the values I provided (and still have a copy of), I signal a configuration change with the destination configuration singleton i registered with change event support. In the Rfc configuration event arguments, I provide type changed and include USER and NAME in the changedParameters. For the thread that triggers it, i get a new RfcDestination from NCo and in there I do see the User property of the Parameters is back to the actual user name, not zeroes. However for other threads that are in the middle of calling something on their reference of RfcDestination after checking it, they get an NCo exception of Rfc Destination is shutdown - cannot for instance get SystemAttributes -.

In the NCo 3 programing guide there is mention of a sample for using NCo in multi-threaded environment. Where may I find / download this sample? Is there an article on best practices / guidelines for multi-threading and NCo?

Accepted Solutions (0)

Answers (1)

Answers (1)

david_burg
Participant
0 Kudos

A couple updates on this:

  1. The user name in the RfcConfigParameters was coming from WCF channel client credentials object, and once that channel is closed WCF will zero the user name. Doing a character by character copy of the user name avoided RfcConfigParameters having a reference on the string which backing array would be zeroed.
  2. It appears that for a few seconds after destination change event of type delete is followed by a destination change event of type change, i.e. a user disconnected then reconnected right after, Rfc destination remains shutdown such that request to the returned destination will fail. I've added a wait of a second - didn't help - then five seconds and the issue went away. This is not a good fix however as I would rather have a deterministic behavior that either once the change event has been issued the Rfc destination is immediately available again, or that NCo has some way for callers to wait until the destination is restored so we don't get an unexpected exception thrown.