I have a block like so:
begin
# some SQL request
rescue Mysql::Error => e
logputs "Mysql::Error occurred, retrying in 10s: #{e.message}"
sleep 10
retry
end
But when a "Lost connection to MySQL server" error occurred, this block was not able to catch it and retry (the MySQL server was restarted). Any idea how I can properly catch this exception?
Thanks!
From your comment it looks like what's happening is that a Mysql::Error exception is being thrown, but then caught by ActiveRecord which then throws an ActiveRecord::StatementInvalid exception (which isn't very helpful behaviour in this case!).
I'd say change your rescue to catch the AR::StatementInvalid exception and see what that does for you.
Are you sure you are rescuing the correct type of exception?
Try using the following code:
rescue StandardError => e
puts e
That should output any exception that is raised and more importantly you will be able to see the specific type. Then you can adjust your rescue statement to be more specific.
Related
I have a CORBA client-server program that is working perfectly. The client can get a servant and call methods remotely.
I would now like to make the server interact with a database using JPA. However everything goes wrong when I add this one line to the server code:
emf.createEntityManager();
The server builds, and it registers to the orbd without error. However when I run the client which tries to connect with the server I get the following exception:
Exception: org.omg.CORBA.OBJECT_NOT_EXIST:
Full exception and stack trace are:
Exception: org.omg.CORBA.OBJECT_NOT_EXIST: ----------BEGIN server-side stack trace----------
org.omg.CORBA.OBJECT_NOT_EXIST: vmcid: SUN minor code: 401 completed: No
at com.sun.corba.se.impl.logging.ActivationSystemException.errorInBadServerIdHandler(ActivationSystemException.java:239)
at com.sun.corba.se.impl.logging.ActivationSystemException.errorInBadServerIdHandler(ActivationSystemException.java:257)
at com.sun.corba.se.impl.activation.ServerManagerImpl.handle(ServerManagerImpl.java:604)
at com.sun.corba.se.impl.orb.ORBImpl.handleBadServerId(ORBImpl.java:1602)
at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.checkServerId(CorbaServerRequestDispatcherImpl.java:407)
at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:182)
at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1700)
at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1558)
at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:940)
at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:198)
at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:712)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:471)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.doWork(SocketOrChannelConnectionImpl.java:1230)
at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:490)
at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:519)
Caused by: com.sun.corba.se.spi.activation.ServerNotRegistered: IDL:activation/ServerNotRegistered:1.0
at com.sun.corba.se.impl.activation.RepositoryImpl.getDBServerDef(RepositoryImpl.java:221)
at com.sun.corba.se.impl.activation.RepositoryImpl.getServer(RepositoryImpl.java:228)
at com.sun.corba.se.impl.activation.ServerManagerImpl.getEntry(ServerManagerImpl.java:350)
at com.sun.corba.se.impl.activation.ServerManagerImpl.handle(ServerManagerImpl.java:566)
... 12 more
To my mind, a call to createEntityManager is logically completely separate from the CORBA networking functionality, so I can't see how this could possible have an impact on the client connecting to the server.
The exception was coming from my EntityManagerFactory. It had nothing to do with the networking, but because I never ran the server until a client connected, no exception occurred until that point.
The exception output was not particularly useful. I found it helpful to comment out all the networking code and just run the server as a stand-alone program from development (much more useful error messages when something goes wrong).
I'm using MySQL server (5.6) database extensively through its .NET connector (6.8.3). All tables are created with MyISAM engine for performance reasons. I have only one process with one thread accessing the DB sequentially, so there is no need for transactions and concurrency.
Please note: this is unlikely to be a timeout configuration issue, because my query is trivial. I did read all timeout related questions (links below). Of course, I may be wrong, but saying just "increase the net_write_timeout parameter" without explaining why exactly it can be relevant here is not an answer.
Some of my tables are created dynamically during program execution so I'm using create on first use idiom, with the following method to check whether the table exists:
private bool TableExists(Space baseSpace, Space extendedSpace)
{
var tableName = GenerateTableName(baseSpace, extendedSpace);
var sqlConnection = this.connectionPool.Take();
this.existsCommand.Connection = sqlConnection;
this.existsCommand.Parameters["#tableName"].Value = tableName.Trim('`');
var result = existsCommand.ExecuteScalar() as long?;
this.connectionPool.Putback(sqlConnection);
return result == 1;
}
The query inside the existsCommand is as follows (broken into two lines here for readability):
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = 'my_schema' AND table_name = #tableName
The value of this.existsCommand.Parameters["#tableName"].Value variable contains the correct name of the table, that already exists in this case ("sample_matches_A_to_A_x").
The this.connectionPool.Take() method returns the first MySqlConnection object from my collection of available connections that meets the following predicate:
private bool IsAvailable(MySqlConnection connection)
{
return connection != null
&& connection.State == System.Data.ConnectionState.Open;
}
Usually this works correctly, for a number of hours and then suddenly an exception occurs on this line:
var result = existsCommand.ExecuteScalar() as long?;
With the following contents:
Fatal error encountered during command execution
Stack trace:
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar()
at implementation.SampleMatchesMySqlTable.TableExists(Space baseSpace, Space extendedSpace) in C:...\SampleMatchesMySqlTable.cs:line 168
Inner exception:
Unable to write data to the transport connection: Software caused connection abort.
Inner exception:
Software caused connection abort.
with ErrorCode equal to 10053 and SocketErrorCode being System.Net.Sockets.SocketError.ConnectionAborted
Stack trace of the innermost exception:
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
I've reviewed the following possible duplicates and unfortunately they don't seem relevant here, except one:
SHOW TABLES encountered Fatal error encountered during command execution
Unfortunately, it doesn't provide enough information to decide whether it is an exact duplicate nor it's answered.
There relate to timeout problems. My query is small, returns only one integer, and searches for a table in a meta-table containing something like 20 other tables.
Fatal error encountered during command execution. in C# when i use Insert Into
https://stackoverflow.com/questions/7895178/fatal-error-in-mysql
MySQL Exception - Fatal Error Encountered During Data Read
Fatal error encountered during data read
Fatal error causing timeout -mysql
ADO.Net Entity framework, Fatal error encountered during data read
Different error regarding reading the resultset:
Fatal error encountered during command execution
Syntax errors and connection string issues:
Mysql Fatal error encountered during command execution
fatal error encountered during execution... during update
Fatal error encountered during command execution
fatal error encountered during command execution during update
fatal error encountered during command execution c# mysql
Fatal error encountered during command execution with a mySQL INSERT
I have Fatal error encountered during command execution
MySql exception was unhandled - Fatal error encountered during command execution
https://stackoverflow.com/questions/24098561/mysql-fatal-error-encountered-during-command-execution-in-c-sharp
Fatal Error Encounter During Command Execution MySQL VB
"Fatal error encountered during command execution." mysql-connector .net
"Fatal error encountered during command execution."
C#, MySQL - fatal error encountered during command execution- Checked other solutions, something I am Missing
Creating a view:
"fatal error encountered during command execution" when trying to add a view from MySQL DB
Reading CSV files:
Fatal error encountered during command execution while importing from csv to mysql
MySQL fatal error encountered during command execution - looping through all csv files in folder for load data local infile
I ended up modifying the IsAvailable method as follows:
private bool IsAvailable(MySqlConnection connection)
{
var result = false;
try
{
if (connection != null)
{
result = connection.Ping();
}
}
catch (Exception e)
{
Console.WriteLine("Ping exception: " + e.Message);
}
return result && connection.State == System.Data.ConnectionState.Open;
}
The .Ping call seems to be better in verifying connection's state then its properties, although it's very poorly documented. From some other sources I've read in the meantime:
an alternative is to run a simple query like SELECT 1 FROM DUAL instead of calling Ping.
Also, there seems that sometimes a DataReader, even though it was disposed (everything is implemented with the using statement), is still attached to the connection for some brief period of time. Because of this I've modified the condition to this:
if (connection != null && connection.State == ConnectionState.Open)
The State property has the Executing value as long as a DataReader is attached to it, so additionally verifying if it's Open at the beginning works fine here.
I have several computers that can render a large report with no issues, however, several other computers cannot render the report and crash reporting services.
We have SQL Server 2008 R2 SP1 and we have observed that the reporting services application's memory usage increases from 300MB to 1,2GB when this report is being rendered.
Here we have the log file when this report crashes:
rshost!rshost!4cf0!06/26/2013-10:33:38:: e ERROR: WriteCallback(): failed to write in write callback.
rshost!rshost!4cf0!06/26/2013-10:33:38:: e ERROR: Failed with win32 error 0x03E3, pipeline=0x00000000063D2400.
rshost!rshost!106c!06/26/2013-10:33:38:: e ERROR: HttpPipelineCallback::SendResponse(): failed async writing response.
rshost!rshost!106c!06/26/2013-10:33:38:: e ERROR: Failed with win32 error 0x03E3, pipeline=0x00000000063D2400.
httpruntime!ReportServer_0-1!106c!06/26/2013-10:33:38:: e ERROR: Failed in BaseWorkerRequest::SendHttpResponse(bool), exception=System.Runtime.InteropServices.COMException (0x800703E3): The I/O operation has been aborted because of either a thread exit or an application request. (Exception from HRESULT: 0x800703E3)
at Microsoft.ReportingServices.HostingInterfaces.IRsHttpPipeline.SendResponse(Void* response, Boolean finalWrite, Boolean closeConn)
at ReportingServicesHttpRuntime.BaseWorkerRequest.SendHttpResponse(Boolean finalFlush)
library!ReportServer_0-1!106c!06/26/2013-10:33:38:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerHttpRuntimeInternalException: RsWorkerRequest::FlushResponse., Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerHttpRuntimeInternalException: An internal or system error occurred in the HTTP Runtime object for application domain ReportServer_MSSQLSERVER_0-1-130167083080132500. ---> System.Runtime.InteropServices.COMException (0x800703E3): The I/O operation has been aborted because of either a thread exit or an application request. (Exception from HRESULT: 0x800703E3)
at ReportingServicesHttpRuntime.BaseWorkerRequest.SendHttpResponse(Boolean finalFlush)
at ReportingServicesHttpRuntime.RsWorkerRequest.FlushResponse(Boolean finalFlush)
--- End of inner exception stack trace ---;
Any idea of what could produce this error? Why this apperars in some computers and everything OK in other?
Thanks in advance.
If you are using the Server Reporting Services (the online interface) and the problem appears for the end users (reading only your report) and the most important you are sure that the report is working properly.
You might try to cache the report first. That might solve your problem and also make the end user more happy since the report will be loading extremely fast.
You can read about caching here: https://learn.microsoft.com/en-us/sql/reporting-services/report-server/caching-reports-ssrs
and here some old instruction how to set up the caching:
http://bhushan.extreme-advice.com/caching-ssrs-reports/
BTW you should also make sure that:
-users have the same rights as you
-the files are up to date and available for all of the users
It is hard to say from here what could be the issue. Try your luck with cache if it won't help to fix this problem... It will definitely bring your reporting and happines of you clients to the new level.
Cheers,
Kacper
Notification Exception: (Env:Production) : : java.lang.String :
PreparedStatementCallback; SQL [ UPDATE txn_tracker set status=?,
schedule_dt=SYSDATE() where txn_id =? and status=? ];
Deadlock found when trying to get lock; try restart
How to cope with this Exception
Please suggest..
You have to catch it and retry the transaction. Some tips to reduce the chance of deadlocks in mysql:
http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
I have a connection to a data base and every time there is a problem connecting I get this error.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '205.178.146.104' (4)' in /data/18/2/77/115/2566441/user/2813515/htdocs/ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php:129
Stack trace:
#0 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:dbname=si...', 'xxx', 'xxx', Array)
#1 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#2 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Abstract.php(459): Zend_Db_Adapter_Pdo_Mysql->_connect()
#3 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `user`', Array)
#4 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Mysq in .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144
The thing is that the database user and password are visible on the page in the error message. Is there a way that I can prevent PHP from showing that info? Or is this happening because I am set up a a developing instead of production?
It is a combination of both. In development, your showing your errors. Which is the primary reason your seeing that.
However, you can catch the exception by testing the connection before the query. Allowing you to handle your own connection failures.
try {
Zend_Db_Table::getDefaultAdapter()->getConnection();
} catch (Zend_Exception $e) {
throw new Zend_Exception("A different error");
}
It is because you are on "developing" (exceptions are shown in browser)
Solution 1: Use Production Environment ;)
Solution 2: Change settings in application.ini
Solution 3: Use an try/catch block for database connect