I'm getting an error in Umbraco that is driving me crazy. Every morning when editors start to work on a Umbraco Content, we start to see an error popping into the Trace Log. "An error occurred looking up media" after some time the SQL server start to give us time out and everything goes to hell.
After spending 3 hours every morning restarting SQL, AppPool and even the Sever, the error start to go away and for the rest of the day everything is at its best. The solution is fast and works like a dream.
When we look at the Trace Log the error message is not informative at all. It doesn't tell anything about what is causing the error to pop. So we don't know if it is backend or frontend related.
Here is the Log Data Detail
Date Mon, 12 Oct 2015, 12:08:37
Level ERROR
Logger umbraco.library
Thread 14
Message
An error occurred looking up media
System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at Umbraco.Core.Persistence.Database.<Query>d__7`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Umbraco.Core.Persistence.Database.Fetch[T](String sql, Object[] args)
at Umbraco.Core.Persistence.Database.Fetch[T](Sql sql)
at Umbraco.Core.Persistence.Repositories.VersionableRepositoryBase`2.GetPropertyCollection(Sql docSql, IEnumerable`1 documentDefs)
at Umbraco.Core.Persistence.Repositories.MediaRepository.ProcessQuery(Sql sql)
at Umbraco.Core.Persistence.Repositories.MediaRepository.PerformGetByQuery(IQuery`1 query)
at Umbraco.Core.Persistence.Repositories.RepositoryBase`2.GetByQuery(IQuery`1 query)
at Umbraco.Core.Services.MediaService.GetDescendants(IMedia media)
at Umbraco.Core.Services.EntityXmlSerializer.Serialize(IMediaService mediaService, IDataTypeService dataTypeService, IUserService userService, IMedia media, Boolean deep)
at umbraco.library.GetMediaDo(Int32 mediaId, Boolean deep)
at umbraco.library.<>c__DisplayClass3.<GetMedia>b__0()
at Umbraco.Core.Cache.CacheProviderExtensions.<>c__DisplayClass1`1.<GetCacheItem>b__0()
at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Lazy`1.get_Value()
at Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, CacheDependency dependency)
at Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles)
at Umbraco.Core.Cache.CacheProviderExtensions.GetCacheItem[T](IRuntimeCacheProvider provider, String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles)
at Umbraco.Core.CacheHelper.GetCacheItem[TT](String cacheKey, TimeSpan timeout, Func`1 getCacheItem)
at umbraco.library.GetMedia(Int32 MediaId, Boolean Deep)
ClientConnectionId:86165857-88e2-4451-ace1-3282756755ba
Who every can come up with a solution to fix this issue, I'll transfer 100$ to your PayPal account.
So pretty please is there anybody out there who knows why this is happening and what we can do about it.
Our current umbraco version is:
7.2.5 assembly: 1.0.5610.18894
This is an old API: umbraco.library.GetMedia and unless you are using XSLT you should definitely not use this API.
Unfortunately due to the nature of what XSLT requires, this will effectively be looking up every media item from your database that is under the ID you are requesting and putting it into cache and generating a giant XML document from the result.
Hrm, yes XSLT is unfortunate but if you want to keep using it, then there are some work-arounds. The reason why this works for you sometimes is because the result of this is cached... which will also occupy a lot of memory too.
I'm assuming you are passing in the 'true' parameter for GetMedia(int MediaId, bool Deep) ? ... otherwise you won't get this issue since passing in false will only return a single media item. If you only require a single media item, then passing in 'false' will fix your issue.
This sounds right! I'm using GetMedia with a "True" option where I need to get all images from a MediaFolder. So now that I know where the issue is I'll get back to it.
Send me your PayPal account to [email protected] and I'll pay you a Big Cold Beer!
Just to confirm that it is working. I rewrote all macros from XSLT to RAZOR that ware using GetMedia, and this morning we haven't had the issue. The server and solution is working perfectly lige every Umbraco site should :)
An error occurred looking up media
Hi Guys!!
I'm getting an error in Umbraco that is driving me crazy. Every morning when editors start to work on a Umbraco Content, we start to see an error popping into the Trace Log. "An error occurred looking up media" after some time the SQL server start to give us time out and everything goes to hell.
After spending 3 hours every morning restarting SQL, AppPool and even the Sever, the error start to go away and for the rest of the day everything is at its best. The solution is fast and works like a dream.
When we look at the Trace Log the error message is not informative at all. It doesn't tell anything about what is causing the error to pop. So we don't know if it is backend or frontend related.
Here is the Log Data Detail
Who every can come up with a solution to fix this issue, I'll transfer 100$ to your PayPal account.
So pretty please is there anybody out there who knows why this is happening and what we can do about it.
Our current umbraco version is: 7.2.5 assembly: 1.0.5610.18894
Hi,
This is an old API:
umbraco.library.GetMedia
and unless you are using XSLT you should definitely not use this API.Unfortunately due to the nature of what XSLT requires, this will effectively be looking up every media item from your database that is under the ID you are requesting and putting it into cache and generating a giant XML document from the result.
Are you using XSLT ?
Hi Shannon
Yes I'm using XSLT. So that means I have to rewrite all macros to use Razor ?
Hrm, yes XSLT is unfortunate but if you want to keep using it, then there are some work-arounds. The reason why this works for you sometimes is because the result of this is cached... which will also occupy a lot of memory too.
I'm assuming you are passing in the 'true' parameter for
GetMedia(int MediaId, bool Deep)
? ... otherwise you won't get this issue since passing in false will only return a single media item. If you only require a single media item, then passing in 'false' will fix your issue.If you require the whole media tree for that node then you'll need to implement some custom xslt extensions and use the UmbracoHelper media access which uses the media cache/lucene to get the data. IIRC you can actually write c# code directly into XSLT files, see: https://our.umbraco.org/wiki/reference/xslt/extend-your-xslt-with-custom-functions/, otherwise you'll need to create a real xslt extension class, for example: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/UmbracoExamine/XsltExtensions.cs#L23
Then you could use the UmbracoHelper.TypedMedia method to iterate the media tree and return the xml you need.
This sounds right! I'm using GetMedia with a "True" option where I need to get all images from a MediaFolder. So now that I know where the issue is I'll get back to it.
Send me your PayPal account to [email protected] and I'll pay you a Big Cold Beer!
Hi Shannon
Just to confirm that it is working. I rewrote all macros from XSLT to RAZOR that ware using GetMedia, and this morning we haven't had the issue. The server and solution is working perfectly lige every Umbraco site should :)
Don't forget to e-mail me you PayPal account.
is working on a reply...