Skip to content
Snippets Groups Projects
Unverified Commit d35e44b4 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #2239 from raman-bt/4200-take3-addfile-deadlock

4200: Deadlock from creating OsAccount instances outside of a transaction
parents b59273f6 4466aaa8
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
*/ */
public class OsAccountInstance implements Comparable<OsAccountInstance> { public class OsAccountInstance implements Comparable<OsAccountInstance> {
private DataSource dataSource; private DataSource dataSource = null;
private final OsAccount account; private final OsAccount account;
private final OsAccountInstanceType instanceType; private final OsAccountInstanceType instanceType;
...@@ -40,18 +40,28 @@ public class OsAccountInstance implements Comparable<OsAccountInstance> { ...@@ -40,18 +40,28 @@ public class OsAccountInstance implements Comparable<OsAccountInstance> {
/** /**
* Construct with OsAccount and DataSource instances. * Construct with OsAccount and DataSource instances.
* *
* @param account The instance account. * @param account The instance account.
* @param dataSource The instance data source * @param dataSource The instance data source
* @param instanceType The instance type. * @param instanceType The instance type.
*/ */
OsAccountInstance(OsAccount account, DataSource dataSource, OsAccountInstanceType instanceType) { OsAccountInstance(OsAccount account, DataSource dataSource, OsAccountInstanceType instanceType) {
this.account = account; this(account, dataSource.getId(), instanceType);
this.dataSource = dataSource; this.dataSource = dataSource;
this.instanceType = instanceType;
dataSourceId = dataSource.getId();
} }
/**
* Construct with OsAccount and DataSource instances.
*
* @param account The instance account.
* @param dataSourceObjId The instance data source object id.
* @param instanceType The instance type.
*/
OsAccountInstance(OsAccount account, long dataSourceObjId, OsAccountInstanceType instanceType) {
this.account = account;
this.dataSourceId = dataSourceObjId;
this.instanceType = instanceType;
}
/** /**
* Construct the OsAccountInstance doing a lazy construction on the data * Construct the OsAccountInstance doing a lazy construction on the data
* source object. * source object.
......
...@@ -527,7 +527,6 @@ public void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, ...@@ -527,7 +527,6 @@ public void createOsAccountInstance(OsAccount osAccount, DataSource dataSource,
*/ */
void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException {
if (osAccount == null) { if (osAccount == null) {
throw new IllegalArgumentException("Cannot create account instance with null account."); throw new IllegalArgumentException("Cannot create account instance with null account.");
} }
...@@ -535,8 +534,29 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou ...@@ -535,8 +534,29 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou
throw new IllegalArgumentException("Cannot create account instance with null data source."); throw new IllegalArgumentException("Cannot create account instance with null data source.");
} }
createOsAccountInstance(osAccount, dataSource.getId(), instanceType, connection);
}
/**
* Adds a row to the tsk_os_account_instances table. Does nothing if the
* instance already exists in the table.
*
* @param osAccount Account for which an instance needs to be added.
* @param dataSourceObjId Data source where the instance is found.
* @param instanceType Instance type.
* @param connection The current database connection.
*
* @throws TskCoreException
*/
void createOsAccountInstance(OsAccount osAccount, long dataSourceObjId, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException {
if (osAccount == null) {
throw new IllegalArgumentException("Cannot create account instance with null account.");
}
// check cache first // check cache first
OsAccountInstance accountInstance = new OsAccountInstance(osAccount, dataSource, instanceType); OsAccountInstance accountInstance = new OsAccountInstance(osAccount, dataSourceObjId, instanceType);
if (osAccountInstanceCache.contains(accountInstance)) { if (osAccountInstanceCache.contains(accountInstance)) {
return; return;
} }
...@@ -551,7 +571,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou ...@@ -551,7 +571,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou
preparedStatement.clearParameters(); preparedStatement.clearParameters();
preparedStatement.setLong(1, osAccount.getId()); preparedStatement.setLong(1, osAccount.getId());
preparedStatement.setLong(2, dataSource.getId()); preparedStatement.setLong(2, dataSourceObjId);
preparedStatement.setInt(3, instanceType.getId()); preparedStatement.setInt(3, instanceType.getId());
connection.executeUpdate(preparedStatement); connection.executeUpdate(preparedStatement);
...@@ -560,7 +580,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou ...@@ -560,7 +580,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou
osAccountInstanceCache.add(accountInstance); osAccountInstanceCache.add(accountInstance);
} catch (SQLException ex) { } catch (SQLException ex) {
throw new TskCoreException(String.format("Error adding os account instance for account = %s, data source object id = %d", osAccount.getUniqueIdWithinRealm().orElse(osAccount.getLoginName().orElse("UNKNOWN")), dataSource.getId()), ex); throw new TskCoreException(String.format("Error adding os account instance for account = %s, data source object id = %d", osAccount.getUniqueIdWithinRealm().orElse(osAccount.getLoginName().orElse("UNKNOWN")), dataSourceObjId), ex);
} finally { } finally {
db.releaseSingleUserCaseWriteLock(); db.releaseSingleUserCaseWriteLock();
} }
......
...@@ -7022,7 +7022,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, ...@@ -7022,7 +7022,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId,
} }
   
if(osAccount != null) { if(osAccount != null) {
osAccountManager.createOsAccountInstance(osAccount, getDataSource(dataSourceObjId), OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection); osAccountManager.createOsAccountInstance(osAccount, dataSourceObjId, OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection);
} }
return new org.sleuthkit.datamodel.File(this, objectId, dataSourceObjId, fsObjId, return new org.sleuthkit.datamodel.File(this, objectId, dataSourceObjId, fsObjId,
...@@ -7034,9 +7034,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, ...@@ -7034,9 +7034,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId,
   
} catch (SQLException ex) { } catch (SQLException ex) {
throw new TskCoreException(String.format("Failed to INSERT file system file %s (%s) with parent id %d in tsk_files table", fileName, parentPath, parent.getId()), ex); throw new TskCoreException(String.format("Failed to INSERT file system file %s (%s) with parent id %d in tsk_files table", fileName, parentPath, parent.getId()), ex);
} catch(TskDataException ex) { } finally {
throw new TskCoreException(String.format("Failed to get DataSource (%d) object while creating OsAccount Instance", dataSourceObjId), ex);
}finally {
closeStatement(queryStatement); closeStatement(queryStatement);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment