WTSVirtualChannelOpenEx sometimes failed? - rdp

I have a rdp plugin used in my C# AxMSTSCLib.AxMsRdpClient7NotSafeForScripting rdp client:
rdp.AdvancedSettings8.PluginDlls = "{7d413ce8-a0a1-42d9-a67b-6d4be4af17c5}";
When I open the channel on server side:
channelHandle = Win32API.WTSVirtualChannelOpenEx(Win32API.WTS_CURRENT_SESSION,
Marshal.StringToHGlobalAnsi(APP_CHANNEL_NAME),
Win32API.WTS_CHANNEL_OPTION_DYNAMIC | 4);
Sometimes ok, sometimes failed with error code = 0x31, no more error description. Is there any problem with my code?

Related

grpc._channel._InactiveRpcError: _InactiveRpcError of RPC that terminated with: status = StatusCode.INTERNAL

This is a gRPC service & client python program. After running the client script it throwing this error. I am pretty new to using APIs/ gRPC in particular. It would be great if I get to know what might be the problem. Installed gRPC library & few supporting libraries too.
Even though the server is running correctly, the communication through gRPC is terminating with the INTERNAL error status code. Running it on localhost.
return _end_unary_response_blocking(state, call, False, None)
File "/home/mark/anaconda3/envs/custom-model-server/lib/python3.8/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INTERNAL
details = "indices[0,350] = 1650751580 is not in [0, 30522)
[[{{node tf_bert_for_sequence_classification/bert/embeddings/Gather}}]]"
debug_error_string = "{"created":"#1629922773.170809502","description":"Error received from peer ipv4:127.0.0.1:8001","file":"src/core/lib/surface/call.cc","file_line":1066,"grpc_message":"indices[0,350] = 1650751580 is not in [0, 30522)\n\t [[{{node tf_bert_for_sequence_classification/bert/embeddings/Gather}}]]","grpc_status":13}"
'''
The solution for this was to check the byte array that was being passed to the function and make sure the length we were taking was of the array itself not in bytes. So we were able to do:
dimensions = len(byte_array)//4

How do I handle session id context uninitialized in Thrift

sorry to bother you guys,
I have a Thrift server program in c++. Whenever a client connects to me, the handshake succeeds, as does the first Thrift command sent, but the second command sent fails with the error "session id context uninitialized".
The client's next command re-establishes the connection and succeeds, but the fourth will fail again with "session id context uninitialized".
The exact error is
TConnectedClient died: SSL_accept: session id context uninitialized (SSL_error_code = 1)
TConnectedClient input close failed: session id context uninitialized (SSL_error_code = 1)
TConnectedClient output close failed: session id context uninitialized (SSL_error_code = 1)
every 'even' command
My problem seems similar to THIS, but I can't seem to figure out how to change the context of my session to set the SSL_OP_NO_TICKET flag.
I tried adding a ServerEventHandler, but I don't think I can change the serverContext that is present there.
Can anyone help me?
Below is the section of main() where I declare and start the server. If more information is needed, please ask. (sorry if I typo-ed any code, I had to retype by hand it here)
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactoryT<TBufferBase>());
::apache::thrift::stdcxx::shared_ptr<My_svrHandler> handler(new My_svrHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new My_svrProcessor(handler));
::apache::thrft::stdcxx::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory(SSL::TLSv1_2));
sslSocketFactory->loadCertificate(certLocation);
sslSocketFactory->loadPrivateKey(keyLocation);
sslSocketFactory->loadTrustedCertificates(CALocation);
sslSocketFactory->authenticate(true);
::apache::thrift::stdcxx::shared_ptr<TServerSocket> serverSocket(new TSSLServerSocket(9090, sslSocketFactory));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<apache::thrift::server::Tserver> server;
::apache::thrift::stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(10);
::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory> threadFactory = ::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
server.reset(new TThreadedPoolServer(processor, serverSocket, transportFactory, protocolFactory, threadmanager));
if(server.get() != NULL)
{
apache::thrift::concurrency::PlatformThreadFactory factory;
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Thread> thread = factory.newThread(serverThreadRunner);
signal(SIGPIPE, SIG_IGN);
thread->start();
while(1){}
server->stop();
thread->join();
server.reset();
}

How to handle errors from reqMktData calls

Are there any examples on the net how to process errors when downloading data from Interactive Brokers using the IBrokers package? I've had a look at the package details and eWrapper and twsCALLBACK seem to handle this but I can't get them to work. For example the code below produces an error and R hangs, the error msg isn't processed. Thanks for any suggestions.
contract <- twsContract(0,
symbol="SPI",
sectype="XXX", #bad sectype
exch="SNFE",
primary="",
expiry= "20181220",
strike="",
currency="AUD",
right="",
local="",
multiplier = "25",
combo_legs_desc = "",
comboleg = "",
include_expired = "",
secIdType = "",
secId = "")
tws <- twsConnect()
data <- reqMktData(tws,contract,snapshot = TRUE)
You should append a "Disconnect" command to you code. Otherwise your program try to build to connections on the same port, that's not possible and it will not terminate.
I don't know the IBroker package very well, please check the command for disconnecting and append it to your code. Refresh your command line and rerun your code.
In addition, connect to IB Gateway instead of TWS by using that port number (check API settings of your IB Gateway application). In the settings choose a detailed Log.
Run your code again (after changing port number) and send your log file. Then I will try to help more. It's hard to help without any error message.

Why does my code run 2 different ways with the exact same code?

I have an application that I have started developing that monitors websocket messages from all clients connected to the websocket server by relaying all messages received from the server to this application.
Problem
When I run my program (In visual studio I hit Start), it builds and starts up perfectly, and does most of the functionality the same everytime. However, I have a common occurance of a portion of code that will not run the same. Below is the small snippet of that code.
msg = "set name monitor"
SendMessage2(socket, msg, msg.Length)
msg = "set monitor 1"
SendMessage2(socket, msg, msg.Length)
Console.WriteLine("We are after our second SendMessage2 function")
I know that the two calls to SendMessage2 are always executed because visual studio's debug console will output the following
We are at the end of the SendMessage2 Sub
We are at the end of the SendMessage2 Sub
We are after our second SendMessage2 function
I also know when it executes correctly because my websocket server will either output one of the two blocks
Output when app runs correctly
Client 4 connected
New thread created
Connection received. Parsing headers.
Message from socket #4: "set name monitor"
Message from socket #4: "set monitor 1"
Output when app runs incorrectly
Client 4 connected
New thread created
Connection received. Parsing headers.
Message from socket #4: "set name monitor"
Notice how the second output is missing the second message from the monitor application.
What have I tried
Using a string variable to call the functions
Calling the functions using static string arguments (not using the variable msg)
SyncLocking the functions separately
SyncLocking inside the SendMessage2 function
Reordering the functions (swapping the strings to change behavior)
TL;DR
Why is it that even when I do not change my code, my program will execute two separate ways? Am I doing something incorrectly when calling my SendMessage2 Sub?
I am all out of ideas. I am willing to try any recommendation to fix this problem.
All code can be found on GitHub here
So I figured it out.
It is actually not the VB application that is messing up. Nor was my server. While debugging I was looking at the number of bytes received by my server and I noticed the following:
Client 4 connected
New thread created
Connection received. Parsing headers.
bytes read: 25
Message from socket #4: "set name monitor"
bytes read: 22
Message from socket #4: "set monitor 1"
Ok great we have 25 bytes from set name monitor and 22 bytes from set monitor 1
Client 4 connected
New thread created
Connection received. Parsing headers.
bytes read: 47
Message from socket #4: "set name monitor"
And boom. Both programs were doing their jobs, sending the correct number of bytes every time and reading the correct number. However, the VB application is sending them so quickly back to back that my server was reading all 47 bytes at a time instead of the separate 25 and 22 bytes.
Solution
I solved this problem by implementing a secondary buffer in my server to store off all bytes after the first message should multiple messages by group like this. Now I check if my secondaryBuffer is empty before reading in new bytes.
Here is a portion of the code used to solve the problem
/*Byte Check*/
for (j=0; j < bytes; j++) {
if (j == 0)
continue;
if (readBuffer[j] == '\x81' && readBuffer[j-1] == '\x00' && readBuffer[j-2] == '\x00') {
secondaryBytes = bytes - j;
printf("Potential second message attached to this message\nCopying it to the secondary buffer.\n");
memcpy(secondaryBuffer, readBuffer + j, secondaryBytes);
break;
}//END IF
}//END FOR LOOP
/**/

Strophe Unrecoverable TLS error

I am developing a simple ejabberd client in C using libstrophe. It connects and begins to handle messages as it's supposed to do.
However, after a while (following two or three pings from the ejabberd server), my connection closes and the status is set to DISCONNECTED. Below is the tail of the debug lines:
xmpp DEBUG Unrecoverable TLS error, 5.
xmpp DEBUG Closing socket.
DEBUG: disconnected event DEBUG Stopping event loop.
event DEBUG Event
oop completed.
I initialize and connect as below.
xmpp_initialize();
/* read connection params */
if( set_xmpp_conn_params( &conn_params ) < 0 ) {
fprintf(stderr, "Could not retrieve connection params from %s\n",
SERVER_CONF_FILE);
return -1;
}
/* initialize the XMPP logger */
xmpp_log = xmpp_get_default_logger(XMPP_LOG_LEVEL);
xmpp_ctx = xmpp_ctx_new(NULL, xmpp_log);
/* create a connection */
xmpp_conn = xmpp_conn_new(xmpp_ctx);
/* login */
xmpp_conn_set_jid(xmpp_conn, conn_params.jid);
xmpp_conn_set_pass(xmpp_conn, conn_params.password);
/* create a client */
xmpp_connect_client( xmpp_conn, conn_params.host, 0,
agent_conn_handler, xmpp_ctx );
/* enter the event loop */
xmpp_run( xmpp_ctx );
/* the code below is executed
whenever connection handler #agent_conn_handler exits */
/* release the connection and context */
xmpp_conn_release(xmpp_conn);
xmpp_ctx_free(xmpp_ctx);
Why am I getting that TLS error message?
Thanks.
Error 5 is SSL_ERROR_SYSCALL. The OpenSSL docs say:
Some I/O error occurred. The OpenSSL error queue may contain more
information on the error. If the error queue is empty (i.e.
ERR_get_error() returns 0), ret can be used to find out more about the
error: If ret == 0, an EOF was observed that violates the protocol. If
ret == -1, the underlying BIO reported an I/O error (for socket I/O on
Unix systems, consult errno for details).
In practice, this may mean the server dropped your connection for some reason. I'd suggest doing a packet trace with WireShark to get more info. For example, we have seen this happen with servers that use the RSA libraries for TLS, when the client offers TLS version 1.1.