diff --git a/src/Server.cpp b/src/Server.cpp
index 7d4b0c3b00..8e464caf10 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -178,13 +178,39 @@ void LyXComm::closeConnection()
 
 int LyXComm::startPipe(string const & file, bool write)
 {
+	static bool stalepipe = false;
 	FileName const filename(file);
-	if (::access(filename.toFilesystemEncoding().c_str(), F_OK) == 0) {
-		lyxerr << "LyXComm: Pipe " << filename << " already exists.\n"
-		       << "If no other LyX program is active, please delete"
-			" the pipe by hand and try again." << endl;
-		pipename_.erase();
-		return -1;
+	if (filename.exists()) {
+		if (!write) {
+			// Let's see whether we have a stale pipe.
+			int fd = ::open(filename.toFilesystemEncoding().c_str(),
+					O_WRONLY | O_NONBLOCK);
+			if (fd >= 0) {
+				// Another LyX instance is using it.
+				::close(fd);
+			} else if (errno == ENXIO) {
+				// No process is reading from the other end.
+				stalepipe = true;
+				LYXERR(Debug::LYXSERVER,
+					"LyXComm: trying to remove "
+					<< filename);
+				filename.removeFile();
+			}
+		} else if (stalepipe) {
+			LYXERR(Debug::LYXSERVER, "LyXComm: trying to remove "
+				<< filename);
+			filename.removeFile();
+			stalepipe = false;
+		}
+		if (filename.exists()) {
+			lyxerr << "LyXComm: Pipe " << filename
+			       << " already exists.\nIf no other LyX program"
+			          " is active, please delete the pipe by hand"
+				  " and try again."
+			       << endl;
+			pipename_.erase();
+			return -1;
+		}
 	}
 
 	if (::mkfifo(filename.toFilesystemEncoding().c_str(), 0600) < 0) {
diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp
index 737bfd9f04..253ba88c2e 100644
--- a/src/support/FileName.cpp
+++ b/src/support/FileName.cpp
@@ -556,6 +556,7 @@ unsigned long FileName::checksum() const
 bool FileName::removeFile() const
 {
 	bool const success = QFile::remove(d->fi.absoluteFilePath());
+	d->refresh();
 	if (!success && exists())
 		LYXERR0("Could not delete file " << *this);
 	return success;
diff --git a/status.16x b/status.16x
index 53cc8d4cc8..d15052c8ce 100644
--- a/status.16x
+++ b/status.16x
@@ -127,6 +127,8 @@ What's new
   to flex-insert so that CharStyles, etc, with spaces in their names 
   will work properly.
 
+- Detect and remove stale lyxpipes on startup (bug 641).
+
 
 * DOCUMENTATION AND LOCALIZATION