diff --git a/source/texk/web2c/luatexdir/lua/luainit.c b/source/texk/web2c/luatexdir/lua/luainit.c
index 5a86b5e064384eb2eee11f5824da0bf09573c1e8..35683fccca3b38e7ffe766df6ead7711c28ed61f 100644
--- a/source/texk/web2c/luatexdir/lua/luainit.c
+++ b/source/texk/web2c/luatexdir/lua/luainit.c
@@ -962,6 +962,7 @@ void lua_initialize(int ac, char **av)
     interactionoption = 4;
     filelineerrorstylep = false;
     haltonerrorp = false;
+    haltingonerrorp = false;
     tracefilenames = 1;
     dump_name = NULL;
     /*tex
diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h
index 6809e8b9c9d63e179f644d25b1eb983ae9dbed7c..9821051cb22057c5ce7061a34f22fb3a8d29830b 100644
--- a/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1,4 +1,4 @@
 #ifndef luatex_svn_revision_h
 #define luatex_svn_revision_h
-#define luatex_svn_revision 7539
+#define luatex_svn_revision 7540
 #endif
diff --git a/source/texk/web2c/luatexdir/tex/errors.c b/source/texk/web2c/luatexdir/tex/errors.c
index ce80df99e7e6b621e8f82e328863d77a6916d299..01b6f44aada8f38cbdab4bfc7a2a94b40a7a9e18 100644
--- a/source/texk/web2c/luatexdir/tex/errors.c
+++ b/source/texk/web2c/luatexdir/tex/errors.c
@@ -436,6 +436,13 @@ void error(void)
         show_context();
     }
     if (haltonerrorp) {
+        /*tex If |close_files_and_terminate| generates an error, we'll end up back
+          here; just give up in that case. If files are truncated, too bad. */
+        if (haltingonerrorp) {
+          /*tex  quit immediately */
+          do_final_end ();
+        }
+        haltingonerrorp=true;
         history = fatal_error_stop;
         jump_out();
     }
diff --git a/source/texk/web2c/luatexdir/tex/mainbody.c b/source/texk/web2c/luatexdir/tex/mainbody.c
index 3d239b5a24de6248d10ce674f10cb957b96f51bf..fd77be07137c7ac341dfbe9b9d6514f6b247f05d 100644
--- a/source/texk/web2c/luatexdir/tex/mainbody.c
+++ b/source/texk/web2c/luatexdir/tex/mainbody.c
@@ -294,6 +294,10 @@ int filelineerrorstylep;
 
 int haltonerrorp;
 
+/*tex already trying to halt? */
+
+boolean haltingonerrorp; 
+
 /*tex current filename is quoted */
 
 boolean quoted_filename;
diff --git a/source/texk/web2c/luatexdir/tex/mainbody.h b/source/texk/web2c/luatexdir/tex/mainbody.h
index 6bb4e66fe41ad2ac1392983d9d2eb18f5092a0f5..011b1958c5e77d999723ed02a6dee40ec100ceee 100644
--- a/source/texk/web2c/luatexdir/tex/mainbody.h
+++ b/source/texk/web2c/luatexdir/tex/mainbody.h
@@ -144,6 +144,7 @@ extern int expand_depth;
 /*extern int parsefirstlinep;*/
 extern int filelineerrorstylep;
 extern int haltonerrorp;
+extern boolean haltingonerrorp;
 extern boolean quoted_filename;
 
 extern int total_pages;