I have a function deployed in Google Cloud Functions (in Java) and while trying to access a Realtime database, there is no response at all - the only hint is that the moment I call:
query.addListenerForSingleValueEvent
I see a log entry:
Failed to find a usable hardware address from the network interfaces; using random bytes: f1:81:5a:ef:89:81:63:07
Here is my code (the function is triggered by receiving a message from the queue):
public class FetchGPWFunction implements BackgroundFunction<PubSubMessage> {
private static final Logger logger = Logger.getLogger(FetchGPWFunction.class.getName());
@Override
public void accept(PubSubMessage message, Context context) {
String data = message.data != null
? "Step 0.1 successful! with message: " + new String(Base64.getDecoder().decode(message.data))
: "Step 0.1 successful!";
logger.info(data);
testFetchData();
}
private void testFetchData() {
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp();
logger.info("Firebase application has been initialized");
}
DatabaseReference databaseReference = FirebaseDatabase.getInstance("https://projectid-rtdb.europe-west1.firebaseio.com").getReference();
Query query = databaseReference.
child("stockData").
child("daily").
child("pl").
child("ALE").
child("quotations").
child("20201012").
child("high");
logger.info("launch query");
final QueryResult queryResult = new QueryResult();
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
logger.info("onDataChange >> got key=" + dataSnapshot.getKey() + " with value=" + dataSnapshot.getValue());
queryResult.setDataSnapshot(dataSnapshot);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
logger.severe("onCancelled >> ERROR! " + databaseError.getMessage() + " details=" + databaseError.getDetails());
queryResult.setError(databaseError);
}
});
int loopSafeGuard = 40;
try {
while (!queryResult.isDone() && (loopSafeGuard > 0)) {
Thread.sleep(500);
loopSafeGuard--;
}
logger.info("Loop ended with results: dataSnapshot=" + queryResult.getDataSnapshot() + " error=" + queryResult.getError());
} catch (InterruptedException ie) {
logger.info("Sleeping interrupted");
}
}
public static class PubSubMessage {
String data;
Map<String, String> attributes;
String messageId;
String publishTime;
}
}
(The query result is just a wrapper:
public class QueryResult {
private DataSnapshot dataSnapshot = null;
private DatabaseError error = null;
...
public boolean isDone() {
return ((dataSnapshot != null) || (error != null));
}
}
And here are logs:
Info 2021-10-21 10:25:26.377 CEST functionFetchGPWData Firebase application has been initialized
Info 2021-10-21 10:25:26.420 CEST functionFetchGPWData launch query
Warning 2021-10-21 10:25:26.829 CEST functionFetchGPWData Failed to find a usable hardware address from the network interfaces; using random bytes: f1:81:5a:ef:89:81:63:07
Info 2021-10-21 10:25:46.463 CEST functionFetchGPWData Loop ended with results: dataSnapshot=null error=null
Debug 2021-10-21 10:25:46.467 CEST Function execution took 21311 ms, finished with status: 'ok'
No errors, no exceptions! - just this weird warning:
{
"insertId": "000000-93ea514e-7271-4fe1-8b71-672b7d028ef7",
"jsonPayload": {
"message": "Failed to find a usable hardware address from the network interfaces; using random bytes: f1:81:5a:ef:89:81:63:07",
"logging.googleapis.com/sourceLocation": {
"method": "defaultMachineId",
"file": "io/netty/util/internal/MacAddressUtil.java"
}
},
"resource": {
"type": "cloud_function",
"labels": {
"function_name": "functionFetchGPWData",
"project_id": "projectid",
"region": "europe-central2"
}
},
"timestamp": "2021-10-21T08:25:26.829Z",
"severity": "WARNING",
"labels": {
"execution_id": "waz43dlcibiy"
},
"logName": "projects/projectid/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"trace": "projectid/traces/b812907333b0200b82f1323a1b5f7dcd",
"sourceLocation": {
"file": "io/netty/util/internal/MacAddressUtil.java"
},
"receiveTimestamp": "2021-10-21T08:25:35.103281657Z"
}
Is this a bug in cloud functions? Am I doing something wrong (more likely ;) ). I refuse to believe that a simple Realtime database read takes more then 20 seconds.