Programmatically setting an image field from hook_node_insert (drupal 7)
node_save() actually invokes hook_node_insert() so calling it from inside that hook probably isn't the best idea (I'm surprised you don't get out of memory errors doing that actually).

Instead you might want to use hook_node_presave(), which is called before the node and associated data is committed to the database:

function MYMODULE_node_presave($node) {
  $image = file_get_contents('http://drupal.org/files/druplicon.large_.png');
  $file  = file_save_data($image, 'public://drupalicon.png',FILE_EXISTS_REPLACE);
  $node-&gt;field_screenshot[LANGUAGE_NONE]['0']['fid'] = $file-&gt;fid;
}


That way you won't have to call node_save() so you won't get the error, and the field data will save with the node as normal.

As hook_node_presave() is called for both inserts and updates, you might want to add a condition in there to check whether the node is new or not (checking $node-&gt;nid will probably suffice). Otherwise you'll end up doing this operation every time the new node is subsequently saved.