Commit 62a6c73f authored by gmantele's avatar gmantele
Browse files

[TAP] Fix unterminated thread after a failed UPLOAD. This bug happened when an...

[TAP] Fix unterminated thread after a failed UPLOAD. This bug happened when an uploaded VOTable reading was interrupted by an exception (like a ParseException)....the streaming thread was not stopped and was still waiting for a notification in order to read the next row.
parent cb6eff4e
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
package tap.data;

/*
 * This file is part of TAPLibrary.
 * 
 * TAPLibrary is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * TAPLibrary is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2015 - Astronomisches Rechen Institut (ARI)
 */

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
@@ -23,11 +42,14 @@ import adql.db.DBType;
 * <p>{@link #getColType()} will return TAP type based on the type declared in the VOTable metadata part.</p>
 * 
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 2.0 (02/2015)
 * @version 2.0 (04/2015)
 * @since 2.0
 */
public class VOTableIterator implements TableIterator {

	/** Message of the IOException sent when the streaming is aborted. */
	protected static final String STREAM_ABORTED_MESSAGE = "Streaming aborted!";

	/**
	 * <p>This class lets consume the metadata and rows of a VOTable document.</p>
	 * 
@@ -42,7 +64,7 @@ public class VOTableIterator implements TableIterator {
	 * </p> 
	 * 
	 * @author Gr&eacute;gory Mantelet (ARI)
	 * @version 2.0 (01/2015)
	 * @version 2.0 (04/2015)
	 * @since 2.0
	 */
	protected static class StreamVOTableSink implements TableSink {
@@ -102,7 +124,7 @@ public class VOTableIterator implements TableIterator {
				 * (because endRows() is always called after acceptRow()...so, it means the iteration has been aborted before the end)
				 * and so the stream reading should be interrupted: */
				if (endReached)
					throw new IOException("Streaming aborted!");
					throw new IOException(STREAM_ABORTED_MESSAGE);

				// Otherwise, keep the given row:
				pendingRow = row;
@@ -336,7 +358,7 @@ public class VOTableIterator implements TableIterator {
					try{
						tb.streamStarTable(input, sink, null);
					}catch(IOException e){
						if (e.getMessage() != null && !e.getMessage().equals("Reading interrupted!"))
						if (e.getMessage() != null && !e.getMessage().equals(STREAM_ABORTED_MESSAGE))
							e.printStackTrace();
					}
				}
+7 −3
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package tap.upload;
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2012-2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -51,7 +51,7 @@ import com.oreilly.servlet.multipart.ExceededSizeException;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (01/2015)
 * @version 2.0 (04/2015)
 * 
 * @see LimitedTableIterator
 * @see VOTableIterator
@@ -148,6 +148,7 @@ public class Uploader {
	 * @see DBConnection#addUploadedTable(TAPTable, tap.data.TableIterator)
	 */
	public TAPSchema upload(final DALIUpload[] uploads) throws TAPException{
		TableIterator dataIt = null;
		InputStream votable = null;
		String tableName = null;
		try{
@@ -159,7 +160,7 @@ public class Uploader {
				votable = upl.open();

				// Start reading the VOTable (with the identified limit, if any):
				TableIterator dataIt = new LimitedTableIterator(VOTableIterator.class, votable, limitUnit, limit);
				dataIt = new LimitedTableIterator(VOTableIterator.class, votable, limitUnit, limit);

				// Define the table to upload:
				TAPColumn[] columns = dataIt.getMetadata();
@@ -175,6 +176,7 @@ public class Uploader {
				dbConn.addUploadedTable(table, dataIt);

				// Close the VOTable stream:
				dataIt.close();
				votable.close();
				votable = null;
			}
@@ -189,6 +191,8 @@ public class Uploader {
			throw new TAPException("URI error while trying to open the VOTable of \"" + tableName + "\"!", e);
		}finally{
			try{
				if (dataIt != null)
					dataIt.close();
				if (votable != null)
					votable.close();
			}catch(IOException ioe){