# Job automatically rescheduled after 1 min when using MSMQ with DTC tr

**URL:** <https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044>\
**Category:** bug?\
**Tags:** msmq, queues\
**Created:** [May 24, 2016, 8:38am UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044 "2016-05-24T08:38:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedja7](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/pedja7/32/634_2.png) [@pedja7](https://discuss.hangfire.io/u/pedja7)\
**Post date:** [May 24, 2016, 8:38am UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044/1 "2016-05-24T08:38:38Z")

</div>

I am using Hangfire 1.5.6 with MSMQ and DTC transactions (in order to use remote MSMQ). The problem is that every long running job (\> 1 min) is automatically rescheduled after 1 min. This is also done in strange order: job is started again before old job has been canceled.  
If I configure Hangfire not to use DTC transactions jobs are running OK.  
In the source code I have noticed that MsmqDtcTransaction is opening TransactionScope. Does this scope needs to be open during job execution? What will happen with SQL server transaction log for long running jobs (this particular job is inserting a lot of data into DB)?  
I have tried with setting transaction timeout in app.config (this also required changes in machine.config):  
`<system.transactions> <machineSettings maxTimeout="02:00:00"/> <defaultSettings timeout="02:00:00" /> </system.transactions>`  
with these changes job was running OK with DTC transactions on.

---

<div class="post-metadata">

**Author:** ![dradovic](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/dradovic/32/208_2.png) [@dradovic](https://discuss.hangfire.io/u/dradovic)\
**Post date:** [May 24, 2016, 2:22pm UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044/2 "2016-05-24T14:22:06Z")

</div>

I have the same problem. Is this a known issue?

---

<div class="post-metadata">

**Author:** ![edgars.sults](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/edgars.sults/32/543_2.png) [@edgars.sults](https://discuss.hangfire.io/u/edgars.sults)\
**Post date:** [August 10, 2016, 8:24am UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044/3 "2016-08-10T08:24:09Z")

</div>

We’re encountering the same problem. A long-running job is hitting the default transaction timeout of 1 minute when using MSMQ and DTC.

Could you make the timeout configurable in the code? Or is there some kind of alternative solution?

EDIT: At the moment we are experimenting with our own implementation of the MSMQ interface for Hangfire, one that doesn’t use transactions. Seems to be working better.

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [August 19, 2016, 4:13pm UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044/4 "2016-08-19T16:13:48Z")

</div>

Guys, I’ve just committed a fix to this, will be released with 1.6.3 soon.

---

<div class="post-metadata">

**Author:** ![pedja7](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/pedja7/32/634_2.png) [@pedja7](https://discuss.hangfire.io/u/pedja7)\
**Post date:** [November 24, 2016, 2:37pm UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044/5 "2016-11-24T14:37:20Z")

</div>

I have tested version 1.6.5 and there is no more timeout of 1 min, instead there is timeout on 10 minutes, which is windows maximal transaction timeout. Did anyone try running job more than 10 minutes with DTC on?

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [November 24, 2016, 2:59pm UTC](https://discuss.hangfire.io/t/job-automatically-rescheduled-after-1-min-when-using-msmq-with-dtc-tr/2044/6 "2016-11-24T14:59:46Z")

</div>

That’s because there is the `maxTimeout` setting. You should set it using `web.config` or `app.config` files as written in the first post of this thread (sometimes you also need to set the `allowExeDefinition` setting as [written here](https://blogs.msdn.microsoft.com/ajit/2008/06/18/override-the-system-transactions-default-timeout-of-10-minutes-in-the-code/)). To check whether it will work for you, you can use the following method. It’s a hack, so it is for testing purposes only.

```auto
internal static bool OverrideTransactionManagerMaximumTimeout(TimeSpan timeOut)
{
    try
    {
        var type = typeof(System.Transactions.TransactionManager);

        var cachedMaxTimeout = type.GetField("_cachedMaxTimeout", BindingFlags.NonPublic | BindingFlags.Static);
        var maximumTimeout = type.GetField("_maximumTimeout", BindingFlags.NonPublic | BindingFlags.Static);

        var syncProperty = type.GetProperty("ClassSyncObject", BindingFlags.NonPublic | BindingFlags.Static);
        if (syncProperty == null)
        {
            return false;
        }

        var syncObject = syncProperty.GetValue(null);

        if (syncObject == null || cachedMaxTimeout == null || maximumTimeout == null)
        {
            return false;
        }

        lock (syncObject)
        {
            cachedMaxTimeout.SetValue(null, true);
            maximumTimeout.SetValue(null, timeOut);
        }

        return true;
    }
    catch (Exception)
    {
        return false;
    }
}

```
