webdriver-io - Cannot init a new session - webdriver-io

Sometimes my selenium grid errors out with this error Session [e4b60cfd-88f9-40ad-a14f-18ba46355a30] was terminated due to TIMEOUT" and appears to be related to this issue in SeleniumHQ:
https://github.com/SeleniumHQ/selenium/issues/1557
In my webdriverio code, I can catch this exception like:
.getAttribute('something').then((onSuccess,onError))
And inside onError, I'm trying end the session like:
client.end().then(()=>{
console.log("ending the session due to error");
});
or
client.session('delete').then(()=>{
console.log("deleting the session due to error");
});
Both of these didn't work. Meaning, I never saw my console messages. Possible that the session was terminated already (based on the previous error message).
However, when I try to run the test again, getting this error:
Cannot init a new session, please end your current session first
Whats the proper way to end the session and handle this issue?

Related

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();
}

A resource failed to call close

I'm getting the android logcat message "A resource failed to call close". I've tracked it down to where that message gets generated. Here's the code:
Properties defaultProperties = new Properties();
URL propURL = Util.class.getClassLoader().getResource(DEFAULT_PROPERTIES_FILE);
if (propURL != null)
{
InputStream is = null;
try
{
// Load properties from URL.
is = propURL.openConnection().getInputStream();
defaultProperties.load(is);
is.close();
}
catch (Exception ex)
{
The message is generated on the call to "defaultProperties.load(is)".
I put a breakpoint on that line, and when I step over that line, the warning message is generated. I'm not the author of the code but that line gets executed at least two times and its the second time when that line gets called when the warning gets generated. I just don't see how under any circumstances that a resource failed to close would be generated on that line. I'm at a lost to explain how or why that error message would be generated there. Any ideas?
After thinking about this, I've come to the conclusion that the problem doesn't have anything to do with the line "defaultProperties.load(is)" causing the warning. Although the message is always generated the second time that line is called, my current thought is that the problem is happening elsewhere but when this line gets called it's probably yielding to some other VM related thread time to process, and that process is detecting that some resource failed to close. I'm concluding that the problem is related to something altogether different and calling that line is the time when the problem surfaces, but it's not what's causing the problem.

How would I print out errors?

In the software called Roblox studio I need help making a script that whenever an error happens in game, it would print out the error again using the normal print function something like this example here:
Local error = —-whatever the error that happened was
Print(error) —- so it just simply prints it back out
Roblox provides a few different ways to keep track of when errors are thrown in your Scripts and LocalScripts.
If you want to observe errors locally in a script, and you know a specific chunk of code may throw errors, you can use pcall() as a try-catch block.
local success, result = pcall(function()
error("this is a test error message")
end)
if not success then
print("An error was thrown!")
print(result) --"this is a test error message"
end
If you want to observe errors across all of your scripts, you can attach a callback to the ScriptContext.Error signal. This signal fires any time any error is thrown. It provides information about the error, including the message, the callstack, and a reference to the script that threw the error.
Warning : ScriptContext.Error only fires in the context of the script that registers it. A Script will only observe errors thrown in server scripts, and registering in a LocalScript will only observe errors thrown on the client.
local ScriptContext = game:GetService("ScriptContext")
ScriptContext.Error:Connect( function(message, stack, context)
print("An error was thrown!")
print("Message : ", message)
print("Stack : ", stack)
print("Context :", context:GetFullName())
end)
Similarly, if you only care about the error messages themselves, you can also observe them being printed out to the Output window using the LogService.MessageOut signal. This signal fires any time anything is logged to Output. This includes messages, warnings, and errors.
local LogService = game:GetService("LogService")
LogService.MessageOut:Connect( function(message, messageType)
if messageType == Enum.MessageType.MessageError then
print("An error was thrown!")
print(message)
end
end)
Use the stderr stream from io library to print debug messages.
-- Define debug function based in print
function debug(...) io.stderr:write(table.concat({...}, '\9') .. '\n') end
-- Debug acts as a regular "print()", but it writes to stderr instead
debug('[filename.lua]', 'debug')
Use "error()" function to print errors.
if true then
error("It should not be true!")
end
If you want to catch errors from a function, use xpcall()
-- Define debug
function debug(...) io.stderr:write(table.concat({...}, '\9') .. '\n') end
xpcall(
function()
local b = {}
-- This will throw an error because you cant index nil values
print(a.b)
end,
function(err)
debug('[xpcall]', err)
end
)
xpcall() wont stop the execution in case of error, so you only need to encapsulate your code in it if you want to catch any unexpected errors at runtime.

Cancel signal (close connection) what could be the cause?

In Kibana of our application, I keep seeing this line of log from org.springframework.web.reactive.function.client.ExchangeFunctions:
[2f5e234b] Cancel signal (to close connection)
The thread is reactor-http-epoll-1 or so.
It could happen in two situations:
when the connection is successful and returns a response, then it does not matter
when for some unknown cause, after 10 seconds, the connection does not return anything, and this line also happens, and period, nothing more. It seems to be a timeout but I am not sure(because the default timeout in my WebClient config is 10s)
What could be the cause of this? Client active drop or server active refusal?
Is the 2nd case a timeout? But not TimeoutException() is thrown afterwards.
I now do a doOnCancel() logging in WebClient to deal with the 2nd case, but then I notice there is case 1, and this doOnCancel() handling does not make sense anymore, because it seems to happen in all cases.
I have the same log. But in my WebClient i returned Mono.empty() and the method signature was Mono< Void>. After changing to Mono< String> the problem was gone.

NHibernate SaveOrUpdate throws NonUniqueObjectException exception

I am currently fixing an old Windows Applications and encountered NHibernate error. I've read and tried few things on the net but end up error.
Here is my code for the ISession:
Public ReadOnly Property session() As ISession
Get
If IsNothing(m_session) Then
m_session = Factory.InitConfiguration.OpenSession()
End If
Return m_session
End Get
End Property
Here is my code for the save button:
Try
session.BeginTransaction()
SetParent(x_object)
'session.clear()
session.Flush()
session.SaveOrUpdate(x_object)
session.Transaction.Commit()
compObj.IsNew = False
Return True
Catch ex As Exception
AppServices.ErrorMessage = ex.Message
session.Transaction.Rollback()
Return False
Finally
'TBA
End Try
So the problem start here, I have this date column as DateTime and AttachmentList.
The current code doesn't have any problem until the user key in the year less than 1753. However the code catch the error properly and display the message and when the user continue to fix the year-typo, it'll still catch the error (while at the watch I already get the new value) until the user close the application and reopened it.
However if I uncomment the session.clear(), it will do just fine, the user may fix their typos and continue to save record, but then when the user do the other action lets say attachment, it will get another error. The attachment action as below:
Add Attachment
Click Save button
Add new attachment
Click Save button
New Error.
So please advice me on what need to be done. I've tried merge, I've tried update,save, evict but end up error. I think my problem is how I arrange the session is the main source of the problem.
It looks like the code you have to handle tries to go on using a session having experienced a failed flush or transaction commit.
This is an anti-pattern. From NHibernate reference:
NHibernate use might lead to exceptions, usually HibernateException.
This exception can have a nested inner exception (the root cause), use
the InnerException property to access it.
If the ISession throws an exception you should immediately rollback
the transaction, call ISession.Close() and discard the ISession
instance. Certain methods of ISession will not leave the session in a
consistent state.
...
The following exception handling idiom shows the typical case in NHibernate applications:
using (ISession sess = factory.OpenSession())
using (ITransaction tx = sess.BeginTransaction())
{
// do some work
...
tx.Commit();
}
Or, when manually managing ADO.NET transactions:
ISession sess = factory.openSession();
try
{
// do some work
...
sess.Flush();
currentTransaction.Commit();
}
catch (Exception e)
{
currentTransaction.Rollback();
throw;
}
finally
{
sess.Close();
}
You must ensure the code does not try to go on using the session after an exception.
Furthermore, it looks like the session stay opened while awaiting user interaction: this is not a recommended pattern. A NHibernate session is normally short lived. Opening a session is cheap.
An usual pattern is to open it when starting to process an event from user input and close it before ending the event processing, in order to not leaving it opened while the user is gone taking a coffee.
Now you may have a hard time changing the application session management, especially if the application retains references to entities and expects them to be still bound to an opened session after having waited for user interaction.
If the choice of keeping the session opened between user interaction was done for "leveraging first level cache" (session entity cache), consider activating second level cache instead.